Link_to:method => :delete不使用jQuery在Rails 3中进行路由以销毁
我正在尝试使它成为笔记的销毁动作的链接:
I'm trying to make this be a link to a destroy action for a note :
<%= link_to "delete", @note, :method => :delete, :confirm => "Are you sure" %>
这只是路由到音符,而不会执行销毁操作...鉴于此:
This just routes to the note and doesn't go through to the destroy action... Whereas this:
<%= button_to "delete", @note, :method => :delete, :confirm => "Are you sure" %>
路由正确.我正在使用jQuery 1.7,并安装了gem'jquery-rails','> = 1.0.12'(其中包括jquery_ujs.js文件).
Does route properly. I'm using jQuery 1.7 and I installed the gem 'jquery-rails', '>= 1.0.12' (which includes the jquery_ujs.js file).
有哪些修复程序可以使link_正常工作?出于某种原因,我有一个较旧的应用程序,这些link_to链接可在其上运行,但我不记得为什么.任何指针?
What fixes are there to make link_to work properly? For some reason, I have an older app on which these link_to links work, but I can't remember why.. Any pointers?
(我真的不想使用button_to.这种样式很烦人,我敢肯定必须有一种方法可以做到这一点.)
(I really don't want to use button_to.. this styling is annoying, and I'm sure that there must be a way to do this..)
更新:使用Rails 3.0.9
UPDATE: Using Rails 3.0.9
您不是从jquery-rails
加载jquery_ujs.js
文件.确保在布局中同时需要jquery
和jquery_ujs
.
You're not loading the jquery_ujs.js
file from jquery-rails
. Ensure that you're requiring both jquery
and jquery_ujs
in your layout.
这两个文件通常包含在app/assets/javascripts/application.js
文件中,该文件包含以下内容:
These two files are typically included in the app/assets/javascripts/application.js
file, which contains this content:
//= require jquery
//= require jquery_ujs
//= require_tree .
如果您不在此行的布局中包含此内容:
If you're not including this in your layout with this line:
<%= javascript_include_tag "application" %>
然后jquery.js
和jquery_ujs.js
文件都不会被包含,因此:method => :delete
请求将无法正常工作.
Then both the jquery.js
and jquery_ujs.js
files won't be included, and so the :method => :delete
requests will not work as intended.