There is a problem here. You used date_format, which is database 
dependent. AFAIK this thing is done using to_char in PostgreSQL and 
Oracle and cast in MSSQL.
I also wanted to fix this issue, but I got stuck here. From what I saw 
RoR doesn't offer us a solution. Maybe somebody else has an idea what to do?

Stuart Smith wrote:
> I have written some code to fix this ticket; how do I get the code
> reviewed? How do I get the code checked in once the changes have been
> agreed?
> 
> This is my first attempt at using ruby and my first attempt at RoR so
> please forgive me if the code is a bit 'amateurish'. 
> 
> Any comments would be most welcome.
> 
> Thanks
> 
> I have included my changes below:
> 
> app/controllers/articles_controller.rb
> 
> require "parsedate"
> include ParseDate
>   @@yr, @@mth, @@dy = nil
> 
>   def archive
>     # date is passed in as Mth YYYY e.g. January 2005
>     # using @@yr @@mth @@dy as class variables so hold values over
> multiple calls so I don't have
>     # to rewrite the index method to handle year and month of archive
> (it will always be set on 1st call)
>     if @params["date"]
>       @archivedate = '01 ' + @params["date"]
>       @@yr, @@mth, @@dy = parsedate(@archivedate)  # might be more
> efficient way to parse the date!
>     end
>     @pages = Paginator.new self, Article.count_by_date(@@yr, @@mth), 10,
> @params['page']
>     @articles = Article.find_all_by_date(@@yr, @@mth, nil,
> @pages.current.to_sql)
>     render_action "index"
>   end
> 
> 
> 
> app/helpers/application_helper.rb
> 
>   def archivelist()
>     archives = Archive.find_dates()
>     render_partial("shared/archives", archives)
>   end
> 
> 
> app/models/archive.rb
> 
> class Archive < ActiveRecord::Base
> 
>   has_many :articles
> 
>   def self.find_dates()
>     @archives=Article.find_by_sql(["SELECT distinct date_format
> (created_at, '%%M %%Y') date from articles ORDER by created_at "])
>   end
> 
> end
> 
> 
> app/models/article.rb
> 
>   belongs_to :archive
> 
> 
> app/views/layouts/articles.rhtml
> 
>   <%= archivelist %>
>   <br/>
> 
> 
> app/views/shared/_archives.rhtml
> 
> <b>Archives</b><br/>
> <% for archive in archives -%>
> <%= link_to
> archive.date, :controller=>"articles", :action=>"archive", 
> :date=>archive.date %><br/>
> <% end -%>
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Typo-list mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/typo-list
> 
> 
From stuart.smith at smsconsulting.wanadoo.co.uk  Tue Apr 12 16:21:59 2005
From: stuart.smith at smsconsulting.wanadoo.co.uk (Stuart Smith)
Date: Tue Apr 12 16:15:43 2005
Subject: [typo] ticket #13 - add Archive articles by month (I hope this
        is      what it means!)
In-Reply-To: <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]>  <[EMAIL PROTECTED]>
Message-ID: <[EMAIL PROTECTED]>

I misunderstood the database dependency issues; I just assumed that
since an ISP/host would run typo against a specific persistent storage
mechanism then a specific version of archive.rb would be installed on
the target system. I just saw this as an extension of the multiple SQL
files to create the initial schema for a specific vendor db.

It would be interesting to see what others make of the problem regarding
vendor specific SQL statements. There are companies that make a living
from 'middleware' to allow the coder to write non-specific SQL (e.g.
RogueWave had something called dbtools.h that I used a long time ago but
that was a real 'pain in the ass' to use).

Thanks

Stuart


> > app/models/archive.rb
> > 
> > class Archive < ActiveRecord::Base
> > 
> >   has_many :articles
> > 
> >   def self.find_dates()
> >     @archives=Article.find_by_sql(["SELECT distinct date_format
> > (created_at, '%%M %%Y') date from articles ORDER by created_at "])
> >   end
> > 
> > end
> > 

Reply via email to