12

次のdate_selectヘルパーがあります。クラスを追加したいのですが、HTMLが生成されません。

<%= date_select :recipient, :birthday, :order => [:day, :month, :year], :start_year => 1920, :end_year => 2013, :class => "input-mini" %>

いくつかの解決策が示唆するように、私もハッシュでそれを試しましたが、構文エラーが発生します:

<%= date_select :recipient, :birthday, :order => [:day, :month, :year], :start_year => 1920, :end_year => 2013, {:class => "input-mini"} %>

いつ、どのようにハッシュでフォーマットするかを本当に理解しているのかわかりません。

4

4 に答える 4

11

これはうまくいくはずです:

<%= date_select :recipient, :birthday, 
:order => [:day, :month, :year], 
:start_year => 1920, 
:end_year => 2013, 
:html=>{:class => "input-mini"} 
%>

更新: Rails 5 の場合

<%= date_select :recipient, :birthday, 
               {
                :order => [:day, :month, :year], 
                :start_year => 1920, 
                :end_year => 2013
               }, 
               {:class => "input-mini"}  %>
于 2012-11-13T18:46:41.727 に答える
1

docsでわかるように、date_selectヘルパーは特定のパラメーターを必要とします。

date_select(object_name, method, options = {}, html_options = {})

私にとっては、メソッドオプションを追加せず、オプションハッシュを{}空のままにしておいてください:

datetime_select(:recipient, {}, {:class => 'custom-select'})

または、:birthdayparam を使用する場合は、次のように単純に使用できます。

datetime_select(:recipient, :birthday, {}, {:class => 'custom-select'})
于 2017-04-12T00:17:23.250 に答える