First, some code style tips...

 >   @from_date = Date.strptime(params[:startdate],"%d/%m/%Y")
 >     @to_date = Date.strptime(params[:enddate],"%d/%m/%Y")

Don't use @ unless other methods really want to see the variable.

 >     @articles = @results.find(:all,
 >                             :conditions => [ "created_at >= ? and
 > created_at <=?",@from_date,@to_date],
 >                             :order => 'created_at desc', :page => {:size
 > => 5, :current => params[:page]})

And always prefer an AR shortcut if you can find one:

   @articles = @results.find_all_by_created_at( from .. to,
                    :order => 'created_at desc',
                     :page => {:size => 5, :current => params[:page]})

 > this works as long as i have the params in the query string in the
 > address. but if i remmove them i want to be able to default to a date
 > range from today back a couple of months.

The big sloppy way would be:

   from = 2.months.ago
     to = Time.now.to_date
   from_date = Date.parse(params[:startdate]) if params[:startdate]
     to_date = Date.parse(params[:enddate])   if params[:enddate]

 > is there a param[:startdate].exists? check i can do???

params.key?(:startdate). But... hash[q] returns nil (usually) if no q key 
exists, so everyone always just treats hash[q] as a boolean.

New question: Could someone make those statements even DRYer? such as with 
.fetch()?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to