rails date_select类不会生效

abs*_*kyy 7 ruby-on-rails

我有以下使用date_select ..

<%= f.date_select :birthday, :order => [:month, :day], :prompt => { :day => 'Select day', :month => 'Select month' }, :html => {:class => "select birthday"} %>
Run Code Online (Sandbox Code Playgroud)

但是这个类没有出现在html中..

<select id="profile_birthday_2i" name="profile[birthday(2i)]">
<select id="profile_birthday_3i" name="profile[birthday(3i)]">
Run Code Online (Sandbox Code Playgroud)

我也试过..

<%= f.date_select :birthday, :order => [:month, :day], :prompt => { :day => 'Select day', :month => 'Select month' }, :class => "select birthday" %>
Run Code Online (Sandbox Code Playgroud)

那也行不通.有任何想法吗?

Dou*_*rer 12

HTML选项是方法的第四个参数date_select,而不是第三个参数中的键.

文档:

date_select(object_name, method, options = {}, html_options = {})
Run Code Online (Sandbox Code Playgroud)

所以你想要:

f.date_select :birthday, { :order => [:month, :day], :prompt => { :day => 'Select day', :month => 'Select month' } }, {:class => "select birthday"} 
Run Code Online (Sandbox Code Playgroud)