Syntax for form_for when building an array from checkboxes

后端 未结 4 993
北海茫月
北海茫月 2020-12-13 04:44

I\'m making a form for an Order object, and the order has many Products, via a join table called OrderProducts. So, we\'ve got something like this:

<% @o         


        
4条回答
  •  醉酒成梦
    2020-12-13 05:00

    I know the author was looking for version 2 answers, but this is the top hit for google and I though I would update:

    One can do this ( I'm using 4.0, don't know how far back it goes ):

    <%= form_for @order do |form| %>
      <%= form.collection_check_boxes(:product_ids, Product.all, :id, :labeling_method ) %>
    <% end %>
    

    For more info: http://edgeapi.rubyonrails.org...

提交回复
热议问题