There are other improvements that you could make here, but the core of
what’s going on is that you’re wrapping the info going back to the
add_to_cart action in a line_item hash. The main change was using
form_for rather than form_tag so that you could wrap the product_id
(you’ll need that, right?) along with the quantity in a line_item hash
(controller’s perspective). To create an instance you’d:
item = LineItem.new( params[:line_item])
in your controller and it’d be loaded with both the quantity AND
product.
HTH,
AndyV
HTH,
AndyV
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.