简体   繁体   English

缺少使用jquery-rails的rails.js

[英]Missing rails.js with jquery-rails

I'm new to Rails 3.1 and recently started a project. 我是Rails 3.1的新手,最近开始了一个项目。 My Gemfile contains jquery-rails like so: 我的Gemfile包含jquery-rails,如下所示:

gem 'jquery-rails'

And indeed, I have verified that it's present (version 1.0.19) in my current RVM gemset (using gem list ). 事实上,我已经在我当前的RVM gemset(使用gem list )中验证了它的存在(版本1.0.19)。

I started to get into Ajax-enabled forms, and from reading various articles and posts from Googling, it appears that I'm supposed to have a file called rails.js in my javascripts folder (I assume this is assets/javascripts/ , and I am using the default asset pipeline). 我开始使用支持Ajax的表单,从Googling阅读各种文章和帖子,看来我应该在我的javascripts文件夹中有一个名为rails.js文件(我假设这是assets/javascripts/ ,并且我正在使用默认资产管道)。

My question actually involves two parts: 我的问题实际上涉及两个部分:

  1. I couldn't find a rails.js file in my project even after bundle install , so I downloaded it from https://github.com/rails/jquery-ujs and placed it in my assets/javascripts/ folder. 即使在bundle install ,我也无法在项目中找到rails.js文件,因此我从https://github.com/rails/jquery-ujs下载了它并将其放在我的assets/javascripts/文件夹中。 Is this the correct thing to do? 这是正确的做法吗?

  2. Upon including rails.js , my Ajax form now submits three times. 在包含rails.js ,我的Ajax表单现在提交了三次。 Upon further investigation it appears as if all my javascript (or jquery???) is getting called three times. 经过进一步调查,似乎我的所有javascript(或jquery ???)被调用了三次。 When I click on the "destroy" link for an object (the kind generated when you rails g scaffold something ), the confirmation pop-up comes up three times as well. 当我点击一个对象的“破坏”链接(当你使用rails g scaffold something来支撑rails g scaffold something时产生的那种)时,确认弹出窗口也会出现三次。 Removing the rails.js file also removes this issue. 删除rails.js文件也会删除此问题。

Any help or advice will be greatly appreciated... I've been searching around Google and SO for hours, and haven't gotten anywhere. 任何帮助或建议将不胜感激...我一直在搜索谷歌和SO几个小时,并没有得到任何地方。 Thanks! 谢谢!

jquery-rails serves jquery and jquery_ujs from inside the gem. jquery-rails从gem内部提供jquery和jquery_ujs。 You don't need to copy these files to assets/javascripts. 您无需将这些文件复制到assets / javascripts。

Make sure you have these two lines in javascripts/application.js: 确保在javascripts / application.js中有这两行:

//= require jquery
//= require jquery_ujs

And have javascript_include_tag 'application' in your layout. 并在您的布局中添加javascript_include_tag 'application'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM