这只是路由到注释,不会进行销毁操作...而这样: :delete, :conf-6ren">
gpt4 book ai didi

jquery - 链接到:method => :delete not routing to destroy in Rails 3 with jQuery

转载 作者:行者123 更新时间:2023-11-30 23:53:49 28 4
gpt4 key购买 nike

我试图使其成为注释销毁操作的链接:

 <%= link_to "delete", @note, :method => :delete, :confirm => "Are you sure" %>

这只是路由到注释,不会进行销毁操作...而这样:

 <%= button_to "delete", @note, :method => :delete, :confirm => "Are you sure" %>

路线是否正确。我使用的是 jQuery 1.7,并且安装了 gem 'jquery-rails', '>= 1.0.12' (其中包括 jquery_ujs.js 文件)。

有哪些修复可以使 link_to 正常工作?由于某种原因,我有一个较旧的应用程序,这些 link_to 链接可以在其上工作,但我不记得为什么......有任何指示吗?

(我真的不想使用button_to..这种样式很烦人,我确信一定有办法做到这一点..)

更新:使用 Rails 3.0.9

最佳答案

您没有从 jquery-rails 加载 jquery_ujs.js 文件。确保您的布局中同时需要 jqueryjquery_ujs

这两个文件通常包含在 app/assets/javascripts/application.js 文件中,其中包含以下内容:

//= require jquery
//= require jquery_ujs
//= require_tree .

如果您不使用此行将其包含在布局中:

<%= javascript_include_tag "application" %>

那么 jquery.jsjquery_ujs.js 文件都不会被包含,因此 :method => :delete请求将无法按预期工作。

关于jquery - 链接到:method => :delete not routing to destroy in Rails 3 with jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9945441/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com