I've litte problem with radiobuttons in SimpleForm.
When i use
= f.association :manufactureType, :collection => ManufactureType.all, :as => :radio
Rails simply generates few radiobuttons, but none of them are selected. I want first radiobutton to be selected by default. How can i make it?
Thanks
If you pass in the manufacture types into the view, you can do the following:
:checked => @manufacture_types[0]
Or
:checked => ManufactureType.first
My example was slightly more complicated, none of the other answers worked for me since there was no collection or model to reference.
= f.input :attending, as: :radio_buttons, :collection => [ ['Yes', true], ['No', false] ], :checked => ['Yes', true]
from op's comment, adding this parameter worked for me:
:checked => 1
Here is an excerpt of my code which works:
= f.input :body_format,
collection: [['markdown', 'Markdown']],
label_method: :last,
value_method: :first,
as: :radio_buttons,
checked: 'markdown', # THIS
required: true
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