将一个CSS类添加到date_select

Mat*_*ler 9 css ruby-on-rails

我有以下date_select助手.我想添加一个类,但它不生成HTML.

<%= date_select :recipient, :birthday, :order => [:day, :month, :year], :start_year => 1920, :end_year => 2013, :class => "input-mini" %>
Run Code Online (Sandbox Code Playgroud)

我也尝试使用哈希,因为一些解决方案建议但我得到一个语法错误:

<%= date_select :recipient, :birthday, :order => [:day, :month, :year], :start_year => 1920, :end_year => 2013, {:class => "input-mini"} %>
Run Code Online (Sandbox Code Playgroud)

不确定我真的了解何时以及如何使用哈希格式化它.

sta*_*p75 29

经验证的答案对我不起作用,有效的是:

<%= date_select
    :recipient,
    :birthday,
    {:order => [:day, :month, :year], :start_year => 1920, :end_year => 2013},
    {:class => "input-mini"}
%>
Run Code Online (Sandbox Code Playgroud)

根据文档更有意义:

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


小智 10

这应该工作:

<%= date_select :recipient, :birthday, 
:order => [:day, :month, :year], 
:start_year => 1920, 
:end_year => 2013, 
:html=>{:class => "input-mini"} 
%>
Run Code Online (Sandbox Code Playgroud)

更新:对于Rails 5

<%= date_select :recipient, :birthday, 
               {
                :order => [:day, :month, :year], 
                :start_year => 1920, 
                :end_year => 2013
               }, 
               {:class => "input-mini"}  %>
Run Code Online (Sandbox Code Playgroud)