Ruby-on-rails 无法在 Rails 4 中的选择表单助手上添加类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21338113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't add class on select form helper in Rails 4
提问by Victor
Using Rails 4. Can't seem to add classto select. I think other attributes like required, autofocusare also not there:
使用 Rails 4。似乎无法添加class到select. 我认为其他属性,如required,autofocus也不存在:
<%= form.select "availability", options_for_select(1..200), required: 'true', autofocus: 'true', class: 'form-control' %>
Output is below:
输出如下:
<select id="event_availability" name="event[availability]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
...
</select>
Any idea? Thanks.
任何的想法?谢谢。
回答by usha
Try this
尝试这个
<%= form.select "availability", options_for_select(1..200), {}, {required: 'true', autofocus: 'true', class: 'form-control'} %>
Possible options for third argument are :promptand :include_blank
第三个参数的可能选项是:prompt和:include_blank
回答by TeckTrack2k
This works for me Pull List:
这对我有用拉列表:
<%= f.select( :user_id, options_from_collection_for_select(@users, :id, :name, (@user.id.nil?) ? nil : @users.id), { :include_blank => true }, {:class => 'span4'}) %>

