删除/销毁不适用于jQuery的Rails 3 [英] Delete / Destroy is not working in rails 3 with jQuery

查看:92
本文介绍了删除/销毁不适用于jQuery的Rails 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的删除/销毁不适用于Rails 3。

My delete/destroy is not working for Rails 3.

不适用于任何脚手架甚至新项目。

Not for any scaffold or even for new projects.

<%= link_to 'Destroy', card, :confirm => 'Are you sure?', :method => :delete %> 

来自这个问题。解决方案是重新安装Firefox。但是我的浏览器也不适合在Chrome,Safari和Opera中使用。

From this question. Solution is Firefox reinstalation. But mine is also not working in chrome, safari or opera.

生成的HTML代码:-

Html code generated:--

 <a href="/categories/1" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a>

PS:请不要说包括默认的JS文件或其他内容。因为我对使用jQuery时对我的全部原型都不感兴趣。

PS: Please don't say include default JS files or something. Because I am not interested in prototype all together, as I am using jQuery.

编辑/更新,重要:这是您的解决方案根本不想使用原型。我在我的项目中只使用jQuery和相应的插件。

EDIT/Update, Important: this is the solution when you don't want to use prototype at all. I am using only jQuery and respective plugins in my project.

人们在回答:首先包括原型等,然后安装一些gem等来消除原型和jQuery之间的冲突。那是垃圾

People are answering: First include prototype etc and then install some gem etc to remove conflicts between prototype and jQuery. That's rubbish.

我已经发布了答案。请先检查一次,然后再选择。为我工作了十多个项目,没有任何问题。您需要做的只是:

I have posted an answer. Please check that once before you go for the option. Worked for me for more than 10 projects without any issues. All you need to do is:

从您的JavaScript目录中删除所有application.js之外的js文件。然后将我在答案中指定的代码粘贴到新文件中,并包含该文件。包括Jquery.js,然后就一切准备就绪了。您无需添加默认的javascript(即原型)或其他其他gem即可消除冲突等。

Remove all the js files from your javascript directory except application.js. Then Paste the code i specified in my answer in a new file and include that file. Include Jquery.js and then you are all set. You don't need to add default javascript (ie: prototype) or some other gem to remove conflicts etc.

推荐答案

我已运行Mohit曾经遇到过同样的问题,也需要在我的JavaScript资产中包含 Unobtrusive JavaScript Library(或 ujs)。在我当前的Rails(v3.2.5)中,将自动提供UJS库。您可以通过在Gemfile中看到以下行来验证这一点:

I ran into the same issue Mohit had and also needed to include the 'Unobtrusive JavaScript Library' (or 'ujs') in my JavaScript assets. In my current Rails (v3.2.5), the UJS library will be provided automatically. You can verify this by seeing the following line in your Gemfile:

gem'jquery-rails'

,然后在您的app / assets / javascripts / application.js文件中添加以下行:

and the following line in your app/assets/javascripts/application.js file:

// = require jquery_ujs

由于我不了解,我删除了 require jquery_ujs 行来自我自己的application.js文件,这花了我一段时间才弄清楚为什么我的 link_to ...,:method => :delete 调用不再起作用!

Since I didn't know any better, I had removed the require jquery_ujs line from my own application.js file, and it took me a while to figure out why my link_to ..., :method => :delete calls weren't working any more!

一旦我理解了这个问题,就很容易将上述两行添加回去各自的文件,一切又开始按预期方式工作。

Once I understood the problem, it was easy to add the above two lines back to their respective files and everything started working as expected again.

这篇关于删除/销毁不适用于jQuery的Rails 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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