In RoR 3, I just want to have a link/button that activates some action/method in the controller. Specifically, if I click on a ‘update_specs’ link on a page, it should go to ‘update_specs’ method in my products controller. I’ve found suggestions to do this on this site:
link_to "Update Specs", :controller => :products, :action => :update_specs
However, I get the following routing error when I click on this link:
Routing Error No route matches {:action=>”update_specs”,
:controller=>”products”}
I’ve read up on routing but I don’t understand why I should have to route this method if all other methods are accessible via resources:products.
You need to create a route for it.
For instance:
Also by default
link_towill look for aGETmethod in your routes. If you want to handle aPOSTorPUTmethod you need to specify it by adding{:method => :post }or{:method => :put }as a parameter, like:Or you can use
button_toinstead oflink_towhich handles thePOSTmethod by default.