Forum: Ruby on Rails how to have default param if loading page the first time

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
500e92cfb666d6757c317a5df7c7e28d?d=identicon&s=25 Shawn Bright (nephish)
on 2007-03-26 21:38
(Received via mailing list)
lo there,
i have a page with a date_select on it. When the date is passed, i
need it to pass back to the same action (reloading the page with a new
date). Now, i want the default date to be yesterday. This is for the
first time the page is hit, but i don't know how to set my controller
up like that.

def pull_records_from_date
    @start = params[:start]
     do some stuff here
end

how do i let the controller know to pick yesterday for a start date
( ruby date object ) if nothing was passed to the action ?

thanks
83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2007-03-26 21:53
(Received via mailing list)
Greatest little operator in Ruby: ||=

def pull_records_from_date
   @start = params[:start]
###
   @start ||= Date.yesterday
###
    do some stuff here
end

Which basically says "if there's nothing here yet, do another assignment
check!"

Jason
500e92cfb666d6757c317a5df7c7e28d?d=identicon&s=25 Shawn Bright (nephish)
on 2007-03-26 21:59
(Received via mailing list)
way cool, thanks very much
sk
E1f43bafda26307a050d11902752b2a6?d=identicon&s=25 Ball, Donald A Jr (Library) (Guest)
on 2007-03-26 23:59
(Received via mailing list)
def pull_records_from_date
  @start = params[:start] || (Date.today - 1).to_s
  ...
end

- donald
500e92cfb666d6757c317a5df7c7e28d?d=identicon&s=25 Shawn Bright (nephish)
on 2007-03-27 12:14
(Received via mailing list)
hey, thanks for this, looks good
sk

On Mar 26, 4:58 pm, "Ball, Donald A Jr \(Library\)"
This topic is locked and can not be replied to.