Sunday, 15 June 2014

How do I set a default checked option with Rails collection_radio_buttons? -



How do I set a default checked option with Rails collection_radio_buttons? -

so i'm trying set first radio button checked default form. can't figure out how it. can of inputs have checked="checked" adding checked: true or checked: 'checked' in html options, in 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, in following:

<%= f.collection_radio_buttons :category_id, @categories, :id, :name, {}, { checked: @category.first } %>

but doesn't work either. none of inputs checked.

any ideas?

i think should marked id checked, alter { checked: @category.first.id }

ruby-on-rails

No comments:

Post a Comment