Rails 4 - checkboxes for has_and_belongs_to_many association

后端 未结 3 2033
悲&欢浪女
悲&欢浪女 2020-12-01 12:29

I recently had a problem getting checkboxes to work for a has_and_belongs_to_many (HABTM) association in Rails 4. I was able to find the information on how to get it working

3条回答
  •  情话喂你
    2020-12-01 13:15

    This is all you need to do for the form: Don't do it manually when there is a built in helper.

    <%= form_for @kennel do |f| %>
      <%= f.collection_check_boxes(:handler_ids, Handler.all, :id, :to_s) %>
    <% end %>
    

提交回复
热议问题