Link_to:method => :delete不使用jQuery在Rails 3中进行路由以销毁 [英] Link_to :method => :delete not routing to destroy in Rails 3 with jQuery

查看:69
本文介绍了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文件.确保在布局中同时需要jqueryjquery_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.jsjquery_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.

这篇关于Link_to:method =&gt; :delete不使用jQuery在Rails 3中进行路由以销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆