开发者

Default values for querystring parameters, the Ruby way?

开发者 https://www.devze.com 2022-12-19 04:21 出处:网络
What\'s the Ruby way to do this? if params[:month] @sele开发者_如何学Gocted_month = params[:month].to_i

What's the Ruby way to do this?

if params[:month]
  @sele开发者_如何学Gocted_month = params[:month].to_i
else 
  @selected_month = Time.now.month
end


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号