如何根据需要设置f.select字段 - rails 5

时间:2016-07-31 23:57:59

标签: html5 ruby-on-rails-5

如何根据需要设置f.select字段?

:required => true无效

<div class="form-group">
<label>Bedrooms</label>
<%= f.select :bed_room, [["1",1], ["2",2], ["3",3], ["4",4], ["5",5], ["6",6], ["7",7], ["8",8], ["9",9], ["10+",10]], prompt: "Select...", class: "form-control", :required => true  %>
</div>

事先提前

1 个答案:

答案 0 :(得分:1)

它就像一个魅力:

<%= f.select :bed_room, [["1",1], ["2",2], ["3",3], ["4",4], ["5",5], ["6",6], ["7",7], ["8",8], ["9",9], ["10+",10]], { prompt: "Select..." }, { class: "form-control", required: true } %>