使用Rails 4.似乎无法将class
添加到select
。我认为required
,autofocus
等其他属性也不存在:
<%= form.select "availability", options_for_select(1..200), required: 'true', autofocus: 'true', class: 'form-control' %>
输出如下:
<select id="event_availability" name="event[availability]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
...
</select>
有什么想法吗?感谢。
答案 0 :(得分:81)
试试这个
<%= form.select "availability", options_for_select(1..200), {}, {required: 'true', autofocus: 'true', class: 'form-control'} %>
第三个参数的可能选项是:prompt
和:include_blank
答案 1 :(得分:2)
这对我有用 拉单:
<%= f.select( :user_id, options_from_collection_for_select(@users, :id, :name, (@user.id.nil?) ? nil : @users.id), { :include_blank => true }, {:class => 'span4'}) %>
答案 2 :(得分:0)
这对我来说很好用:
<%= f.select(:"task_day", ["Today", "Tomorrow", "Day After Tomorrow"], { selected: "Today" }, {required: 'true', class: 'form-control'}) %>