Sunday, 15 September 2013

Rails, nested attributes, created in new action,

Rails, nested attributes, created in new action,

I have a order system where a user selects products that's being saved in
a cookie. It is then retrieved by the system when continued to the order
page.
@order = Order.new
unless @cart.nil?
@cart.each do | product |
@order.quantities.new :product => product, :quantity => 1
end
However I want the user to be able to update the quantity which is a field
in the quantity model that belongs to product and order.
How can I access this newly made "@order.quantities" in my form view?
<%= simple_form_for(@order) do |f| %>
<%= f.error_notification %>
....

No comments:

Post a Comment