Rails - Default selected radiobutton in SimpleForm :collection

后端 未结 4 612
一向
一向 2020-12-06 05:22

I\'ve litte problem with radiobuttons in SimpleForm.

When i use

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


        
相关标签:
4条回答
  • 2020-12-06 05:48

    from op's comment, adding this parameter worked for me:

    :checked => 1
    
    0 讨论(0)
  • 2020-12-06 05:49

    If you pass in the manufacture types into the view, you can do the following:

    :checked => @manufacture_types[0]
    

    Or

    :checked => ManufactureType.first
    
    0 讨论(0)
  • 2020-12-06 06:03

    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
    
    0 讨论(0)
  • 2020-12-06 06:06

    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]
    
    0 讨论(0)
提交回复
热议问题