Rob Jefferies
Rob Jefferies

Reputation: 254

Default values for querystring parameters, the Ruby way?

What's the Ruby way to do this?

if params[:month]
  @selected_month = params[:month].to_i
else 
  @selected_month = Time.now.month
end

Upvotes: 2

Views: 168

Answers (1)

Pete
Pete

Reputation: 18075

something like:

@selected_month = (params[:month] || Time.now.month).to_i 

the to_i could be a bit redundant on the end for Time.now.month, but it would eliminate the if/else logic

Upvotes: 2

Related Questions