Reputation: 17834
routes.rb
resources :carts do
resources :cart_items
end
rake routes:
cart_cart_items POST /carts/:cart_id/cart_items(.:format) cart_items#create
When I click on the link, it should create new item in cart_items:
link_to 'Add to Cart', '#'
I need help with this link. Also how to pass :cart_id through the link.I'm a newbie to rails. Thanks in advance.
Upvotes: 0
Views: 24
Reputation: 9691
Assuming you have @cart
, then doing link_to 'Add to Cart', cart_path(@cart)
will suffice.
Upvotes: 1