Rails 3 link or button that executes action in controller

最后都变了- 提交于 2019-11-30 09:14:18

You need to create a route for it.

For instance:

resources :products do
  put :update_specs, :on => :collection
end

Also by default link_to will look for a GET method in your routes. If you want to handle a POST or PUT method you need to specify it by adding {:method => :post } or {:method => :put } as a parameter, like:

link_to "Update Specs", {:controller => :products, :action => :update_specs}, {:method => :put }

Or you can use button_to instead of link_to which handles the POST method by default.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!