Creating nested fields for column on assignment table?
- by H O
I have three models, that represent a many to many relationship - Product, Sale and Product_sale.
I have a nested form that allows me to create new products from the sale form - so far, so good. I have, however, added some additional fields to the assignment table - price, for example.
How can I set the price on the assignment table from the product form, when it is nested in the sale form? I currently have the code below:
<%= sale.fields_for :products do |products_builder| %>
<%= render :partial => "products/form", :locals => {:f => products_builder, :form_actions_visible => false} %>
<% end -%>
I could nest a Product_sale form within the product form, but this would create a new product_sale, which is not what I am looking for.
I will most likely need to nest the price field within the product form, to ensure that it updates the correct assignment record (since there could be multiple products on one sale form).
How can I use a fields_for loop on the product form to update the existing assignment record that is built when I do @sale.products.build? The assignment record will not yet be saved, so I can not access it using a where clause and edit it that way.
Thanks!