Alain Goldman
Alain Goldman

Reputation: 2908

Making rails button_to link to a path with a parameter

I am trying to set up a button that goes to a path but I cannot figure out what to set the path to. Currently I have it set up like this:

= button_to "buy" , product_card_path, :method => "get"

but I get an error.

No route matches {:action=>"card", :controller=>"products"}

This is the path in the rake routes:

product_card GET   /products/:product_id/card(.:format)    products#card

How do I make a button_to go to a path that requires a parameter?

Upvotes: 1

Views: 8173

Answers (1)

Pierre-Louis Gottfrois
Pierre-Louis Gottfrois

Reputation: 17631

Try:

= button_to "buy" , product_card_path(your_product_instance), method: :get

Not sure whether or not the method: :get is necessary here.

Upvotes: 5

Related Questions