Use the ternary/comparison operator. I've removed your strptime stuff, but the idea is like so:
@from_date = params[:startdate] ? params[:startdate] : (Time.now - 3.months.ago) @to_date = params[:enddate] ? params[:enddate] : Time.now "If params[:startdate], then @from = params[:startdate], else @from = time.now - 3.months.ago" -eric On Feb 22, 10:34 am, Dave Smith <[email protected]> wrote: > hi folks. > > i want to check if a param exists if not to set it to a default value > for my date range filter. in my controller i have: > > @from_date = Date.strptime(params[:startdate],"%d/%m/%Y") > @to_date = Date.strptime(params[:enddate],"%d/%m/%Y") > > @articles = @results.find(:all, > :conditions => [ "created_at >= ? and > created_at <=?",@from_date,@to_date], > :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. > > is there a param[:startdate].exists? check i can do??? > > any help asap would be great!! > -- > Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

