How to have default param if loading page the first time


#1

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


#2

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


#3

way cool, thanks very much
sk


#4

def pull_records_from_date
@start = params[:start] || (Date.today - 1).to_s

end

  • donald

#5

hey, thanks for this, looks good
sk

On Mar 26, 4:58 pm, “Ball, Donald A Jr (Library)”