So I'm trying to set the first radio button as checked by default for a form. I can't figure out how to do it. I can get all of the inputs to have checked="checked"
by adding checked: true or checked: 'checked' in the html options, as in the following:
<%= f.collection_radio_buttons :category_id, @categories, :id, :name, {}, { checked: true } %>
<%= f.collection_radio_buttons :category_id, @categories, :id, :name, {}, { checked: 'checked' } %>
I've tried specifying checked: @category.first
, as in the following:
<%= f.collection_radio_buttons :category_id, @categories, :id, :name, {}, { checked: @category.first } %>
But that doesn't work either. None of the inputs are checked.
Any ideas?
I think you should marked id
to be checked, so change to { checked: @category.first.id }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With