I would like to use a select box to display and edit a boolean model attribute. I realize that perhaps checkboxes or radio buttons are a more idomatic way to do this in html but I would like to use a select box.
What I want to do is to map the selected value in the box to the existing value of the attribute when the form displays. I am having trouble figuring out how do to this and the examples I can find are not explicit enough for me to discern how this is done, or if it is possible.
I have discovered that if one prefaces the select with the form partial variable 'f' then one gets a series of obsure errors about an undefined 'merge' method, while removing this and going with a bare select call avoids the problem and otherwise seems to work. Odd, but there it is.
Consequently, presently the structure looks something like this:
</b><br />
<%= select :is_invoicable, [ ['Yes', 'true' ], ['No', 'false' ], ], {}, # select options :id => 'select_is_invoicable', :size => 1, :title => 'May invoices be issued in this currency?' -%> </p>
What I want to accomplish, of course, is to have the current value of is_invoicable (true or false) used to set the selected attribute of the option to either Yes or No as appropriate. I nonetheless want both options available in the drop down. I cannot seem to hit upon the exact syntax to do this and the examples in the options_for_select api do not provide me with much guidance. From them I gathered that this would work:
], currency_detail.is_invoicabe.to_s, # select options :id => 'select_is_invoicable',
But that produces this in the view:
<select id="is_invoicable_YestrueNofalse" name="is_invoicable[YestrueNofalse]"> <option value="false">false</option></select>
When what I was looking for was this:
<select id="select_is_invoicable" name="currency [is_invoicable]" size="1" title="May invoices be issued in this currency?"> <option value="true">Yes</option> <option selected="selected" value="false">No</option></
I would really appreciate guidance on how this is done.