Align checkboxes for f.collection_check_boxes with Simple_Form

前端 未结 4 2046
醉梦人生
醉梦人生 2020-12-16 18:08

I am using RoR and I am using the Simple_Form gem for my forms. I have an object relation whereby a User can have multiple Roles, and during creation, the admin can select

4条回答
  •  别那么骄傲
    2020-12-16 18:56

    This was the first SO page for a DDG search with 'rails collection_check_boxes bootstrap', but it's not about Bootstrap, but here is a solution for Bootstrap 4 anyways.

    This works with plain Rails and Bootstrap 4, no gem required. collection_check_boxes is a plain Rails method.

      .form-group
        =f.label :industry_interest
        %br
        =f.collection_check_boxes :industry_interest, Industry.all, :id, :name do |cb|
          =cb.check_box 
          =cb.label
          %br
    

    or

      .form-group
        =f.label :industry_interest
        =f.collection_check_boxes :industry_interest, Industry.all, :id, :name do |cb|
          .form-check
            =cb.label class: 'form-check-label' do
              =cb.check_box class: 'form-check-input'
              =cb.text 
    

    They look identical.

    https://v4-alpha.getbootstrap.com/components/forms/#checkboxes-and-radios

提交回复
热议问题