I’ve created a form in my Rails project with scaffold.
All the fields are strings or text, and some of them I’ve declared in the view as select fields, for example:
<div class="field">
<%= f.label :device %><br />
<%= f.select :device, options_for_select([["iPhone", "iPhone"], ["iPad", "iPad"], ["All", "All"]]) %>
</div>
Creating and viewing the elements there’s no problem. But when I’m editing the fields, the loaded values in the form are the default, not the saved values.
How to solve it?
You are incorrectly using options_for_select, which returns HTML options text, when in fact the f.select call just wants the array.
This will work for you: