rails link_to remote with params

守給你的承諾、 提交于 2019-12-22 09:57:33

问题


I'd like to trigger a remote action for a model using a link. Basically all this link needs to do is trigger a method with one parameter.

Here's my code:

= link_to 'Move Up', reorder_collection_folder_path(@collection, folder), :reorder => :up, :remote => true

This does trigger the Folders#reorder controller action as expected, but the :reorder param is not being passed through. My log says:

Started GET "/collections/1/folders/1/reorder" for 127.0.0.1 at 2011-03-01 18:03:31 -0600
  Processing by FoldersController#reorder as JS
  Parameters: {"collection_id"=>"1", "id"=>"1"}

So, how can I pass a parameter through a remote link? What am I doing wrong here?


回答1:


Found the solution.

For remote links the code should be:

= link_to 'Move Up', reorder_collection_folder_path(@collection, folder, :reorder=>:up), :remote => true

IE the params need to go inside the path helper.



来源:https://stackoverflow.com/questions/5161952/rails-link-to-remote-with-params

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