Radio buttons on Rails

后端 未结 5 885
迷失自我
迷失自我 2020-12-12 19:08

Similar to this question: Checkboxes on Rails

What\'s the correct way of making radio buttons that are related to a certain question in Ruby on Rails? At the moment

5条回答
  •  温柔的废话
    2020-12-12 19:24

    Using Haml, getting rid of needless br tags, and nesting inputs within label so that they may be selected without matching labels to ids. Also using form_for. I would consider this to be following best practices.

    = form_for current_user do |form|
      .form_row
        %label Theme:
        - [ 'plain', 'desert', 'green', 'corporate', 'funky' ].each do |theme|
          %label
            = form.radio_button(:theme, theme)
            = theme.humanize
    

提交回复
热议问题