Rajdeep Singh
Rajdeep Singh

Reputation: 17834

Passing parameters with links

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

Answers (1)

Benjamin Tan Wei Hao
Benjamin Tan Wei Hao

Reputation: 9691

Assuming you have @cart, then doing link_to 'Add to Cart', cart_path(@cart) will suffice.

Upvotes: 1

Related Questions