Rails - default beacon in SimpleForm: collection

I have a problem with radio objects in SimpleForm.

When i use

= f.association :manufactureType, :collection => ManufactureType.all, :as => :radio 

Rails simply generate several radio objects, but none of them are selected. I want the first radio balloon to be selected by default. How can i do this?

thank

+13
ruby-on-rails ruby-on-rails-3 simple-form
Jun 25 2018-11-11T00:
source share
4 answers

If you pass production types into a view, you can do the following:

 :checked => @manufacture_types[0] 

or

 :checked => ManufactureType.first 
+39
Jul 11
source share

My example was a bit more complex, none of the other answers worked for me, since there was no collection or model for the link.

 = f.input :attending, as: :radio_buttons, :collection => [ ['Yes', true], ['No', false] ], :checked => ['Yes', true] 
+9
Mar 26 '14 at 7:04
source share

from the op comment by adding this parameter for me:

 :checked => 1 
+5
Mar 12 '13 at 19:43
source share

Here is a snippet of my code that works:

 = f.input :body_format, collection: [['markdown', 'Markdown']], label_method: :last, value_method: :first, as: :radio_buttons, checked: 'markdown', # THIS required: true 
+2
Jan 26 '16 at 8:46
source share



All Articles