Reputation: 2224
I'm trying to include a boolean value as a dropdown box using the following code in my edit view:
<div class="col-md-8">
<%= f.select :match, options_for_select([['On', true], ['Off', false]]), class: 'form-control input-md' %>
</div>
However I'm experiencing two problems:
1.It does not display the correct value. Even when the user's value is false
, it still displays On
.
2.It does not implement the styling. The inspector shows that it implements it as follows:
<div class="col-md-8">
<select name="user[match]" id="user_match">
<option value="true">On</option>
<option value="false">Off</option>
</select>
</div>
What am I doing wrong?
Upvotes: 1
Views: 1150
Reputation: 1191
Do it like this:
<%= f.select :match, options_for_select([['On', true], ['Off', false]], selected: your_object.match),{}, {class: 'form-control input-md'} %>
Upvotes: 5