Topic: Restful Cart

I'm making a little demo app to help me understand REST with "Has many through" a bit better.
I have Products and Carts connected through line_items.

Now the way I understand it, if I want to add a Product to a Cart, I would invoke the create method in the Line_item controller. Is this correct?

Do I just add a link to the create method for Line_item and pass in the id of the Product as a param? If so does anyone know the syntax for doing this?

Thanks,
Seth

Last edited by learc83 (2007-05-23 13:17:58)

Re: Restful Cart

learc83 wrote:

Now the way I understand it, if I want to add a Product to a Cart, I would invoke the create method in the Line_item controller. Is this correct?

Yep.

learc83 wrote:

Do I just add a link to the create method for Line_item and pass in the id of the Product as a param? If so does anyone know the syntax for doing this?

Like this:

<%= link_to 'add product to cart', line_items_path(:product_id => product), :method => :post

The "post" method part is important so it is sent as a POST request.

Railscasts - Free Ruby on Rails Screencasts

Re: Restful Cart

Sweet, thanks for the help.

I would have never figured out to add the params as an argument to line_items_path.