简体   繁体   中英

rails link_to remote with params

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM