I\'m trying to create some radio buttons and I\'m not sure how to. Following this question I\'ve got it set up working almost correct, but I\'m new to this and not sure why
see label(object_name, method, content_or_options = nil, options = nil, &block)
<div class="field">
<%= f.label :autolyse %><br />
<%= f.label :autolyse, "Yes", :value => "true" %>
<%= f.radio_button :autolyse, true %>
<%= f.label :autolyse, "No", :value => "false" %>
<%= f.radio_button :autolyse, false, :checked => true %>
</div>
If you want to keep selected the option chosen by the user, you should validate the param, would be something like this:
<div class="field">
<%= f.label :autolyse %><br />
<%= f.label :autolyse, "Yes", :value => "true" %>
<%= f.radio_button :autolyse, true, !!params[:autolyse] %>
<%= f.label :autolyse, "No", :value => "false" %>
<%= f.radio_button :autolyse, false, !!params[:autolyse] %>
</div>
If you want to do it from the object properties you just replace the params variable for the object property:
<div class="field">
<%= f.label :autolyse %><br />
<%= f.label :autolyse, "Yes", :value => "true" %>
<%= f.radio_button :autolyse, true, !!@object.autolyse %>
<%= f.label :autolyse, "No", :value => "false" %>
<%= f.radio_button :autolyse, false, !!@object.autolyse %>
</div>