Rails中的link_to remote如何传递参数

4

我希望通过一个链接来触发模型的远程操作,这个链接只需要触发一个带有一个参数的方法。

下面是我的代码:

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

这确实触发了Folders#reorder控制器的操作,但是:reorder参数没有被传递。我的日志显示:

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"}

那么,我如何通过远程链接传递参数?我在这里做错了什么?
1个回答

7

找到了解决方法。

对于远程链接,代码应该是:

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

即参数需要放在路径助手内。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接