Rails如何在link_to_remote中调用另一个控制器

发布于 2024-08-06 00:35:31 字数 97 浏览 5 评论 0原文

如何使用 link_to_remote

:url => 调用不同控制器的操作{:控制器=> "帖子", :action => “更新”}不起作用

how to call a different controller's action using link_to_remote

:url => {:controller => "Posts", :action => "update"} doesn't work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌上芳菲 2024-08-13 00:35:31

方法:

link_to_remote(name, options = {}, html_options = nil)

传入一个哈希值,如:

link_to_remote "hug kittens", { :url => { :controller => 'kittens', :action => 'show' } }

作为第二个参数(选项)。已验证。

结果:

<a onclick="new Ajax.Request('/kittens/hug', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('/BdZwHdC/QqtBJsdCU+cCHxabHj/QHUT6i8ggbr5CtY=')}); return false;" href="#">hug kittens</a>

您的实现问题可能是没有“真正的”update-url(除非您手动创建了一个)。请查看您的编辑表单的网址。它实际上是对“posts/:post_id”的后请求。

the method:

link_to_remote(name, options = {}, html_options = nil)

passing in a hash like:

link_to_remote "hug kittens", { :url => { :controller => 'kittens', :action => 'show' } }

as the second argument (options) works. verified.

the result:

<a onclick="new Ajax.Request('/kittens/hug', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('/BdZwHdC/QqtBJsdCU+cCHxabHj/QHUT6i8ggbr5CtY=')}); return false;" href="#">hug kittens</a>

The problem with your implementation might be, that there is no "real" update-url (except you created one by hand). Please have a look at the url of your edit-form. It's actually a post-request to "posts/:post_id".

独﹏钓一江月 2024-08-13 00:35:31
<%= link_to_remote "Save", :url=>{:controller => "Posts", :action => "update"}, :update=>"div_id" %>
<%= link_to_remote "Save", :url=>{:controller => "Posts", :action => "update"}, :update=>"div_id" %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文