O people, I am trying to understand the documentation and I am looking for an example, but I am getting damaged.
There is only one form in the cart to update this quantity. However, the updated quantity is not being saved in the database - it always creates 0 volumes. help please.
Form
& lt; @ Cart.line_items% & gt; In line_item for% & lt;% form_for: lineitems ,: url = & gt; {: Controller = & gt; "Line_itum",: action => "Cart_update" ,: id = & gt; "# {Line_item.product_id}"}. L & Gt%; & Lt;% = l.text_field: Quantity: Size = & gt; '3' ,: Price = & gt; Line_item.quantity% & gt; & Lt;% = l.submit 'cart_update'% & gt; & Lt;% end% & gt; Route
map.connect 'line_item_update',: admin = & gt; 'Line_itim',: action => 'Cart_update' Administrator
def cart_update @product = Product.find (params [: id]) Item = LineItem .find_or_create_by_cart_id (: cart_id = & gt; current_cart.id ,: product_id = & gt; @ product.id ,: quantity = & gt; 0 ,: unit_price = & gt; @products.price) item.quantity = (param [ : Quantity]) .to_i item. Save redirect_to: controller = & gt; To get started you have to change the scene in such a way. The end of the 'product'
:
Lt;% form_for: lineitems ,: url = & gt; {: Controller = & gt; "Line_itum",: action => "Cart_update" L & Gt%; & Lt;% @ cart.line_items.each_with_index | Line_item, index | & Gt%; & Lt;% fields_for "@ cart.line_items [# {index}]", line_item | I | & Gt%; & Lt;% = i.text_field: Quantity: Size = & gt; '3' ,: Price = & gt; Line_item.quantity% & gt; & Lt;% end% & gt; & Lt;% end% & gt; & Lt;% = l.submit 'cart_update'% & gt;