我想要日期选择框,默认选中空白选项
我使用了以下date_select助手,但没有一个按预期工作。 我想要选择空白选项默认选择日期选择框。 使用以下所有代码,我得到选择框,但选择了当前日期。 我在轨道上2.3.2
{:day => nil, :month => nil, :year => nil} %> { :day => 'Select day', :month => 'Select month', :year => 'Select year' }) %> { :day => nil }) %> true, :order => [:day, :month, :year] %>
更容易做到这一点:
<%= f.date_select :featured_at, {:include_blank => true, :default => nil} %>
<%= f.label :expired %>
<%= f.datetime_select :expired,:prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' } %>
适合我
另外, prompt: true
也可以:
<%= f.date_select :deadline, {order: [:day, :month, :year], prompt: true} %>
在大多数情况下day, month, year
最好显示day, month, year
而不是空白。