带参数的 Rails link_to 远程
我想使用链接触发模型的远程操作。基本上,这个链接所需要做的就是触发一个带有一个参数的方法。
这是我的代码:
= 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"}
那么,如何通过远程链接传递参数?我在这里做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了解决方案。
对于远程链接,代码应该是:
IE 参数需要进入路径助手内部。
Found the solution.
For remote links the code should be:
IE the params need to go inside the path helper.