调用select_month时设置默认值

时间:2011-12-14 16:18:56

标签: ruby-on-rails ruby-on-rails-3

我无法使用select_month计算如何将默认月份设置为4。不知道我做错了什么。谢谢。

select_month(Date.today,  
             :field_name => 'month', 
         :use_month_numbers => true, 
         :html_options => { :selected => '4'})

3 个答案:

答案 0 :(得分:5)

我认为你需要使用Date.new(2011,4)而不是Date.today来设置默认值

select_month(Date.new(2011, 4),  
             :field_name => 'month', 
             :use_month_numbers => true)

答案 1 :(得分:1)

我通过使用以下方式在我的信用卡表单中实现了这一目标:

select_month 6, { add_month_numbers: true }

以6月为默认值。我使用它来渲染用户在重新渲染cc表单时选择的月份。我实际上并没有硬编码那个6。

答案 2 :(得分:0)

我只需使用当前日期即可获得此信息,在我的信用卡表格中效果很好:

select_month Date.today.month, {add_month_numbers: true}
相关问题