迁移到 Rails 3.1 期间 javascript_include_tag 中的 jQuery 失败
我正在尝试将应用程序从 Rails 3 迁移到 3.1,但遇到了 jQuery 问题。错误如下。如果我删除'javascript_include_tag“application”'一切正常(没有javascript),所以与javascript相关的东西丢失了。
Showing C:/.../app/views/layouts/application.html.erb where line #7 raised:
couldn't find file 'jquery'
(in C:/.../app/assets/javascripts/application.js:7)
Extracted source (around line #7):
4: <title><%= @title unless @title.blank? %></title>
5: <!-- %= render 'layouts/stylesheets' % -->
6: <%= stylesheet_link_tag "application" %>
7: <%= javascript_include_tag "application", :debug => true %>
8: <%= csrf_meta_tags %>
9: </head>
10: <body>
在我的 Gemfile 中,我有 jquery-rails 的条目:
source 'http://rubygems.org'
gem 'rails', '3.1.0'
gem 'jquery-rails'
....
在 application.js 中:
// This is a manifest file .......
//
//= require jquery
//= require jquery_ujs
//= require_tree .
//
据我所知,这是在 Rails 3.1 中使用 jQuery 的唯一要求。
我缺少什么?
I am trying to migrate an application from Rails 3 to 3.1 and having problems with jQuery. The error is bellow. If I remove 'javascript_include_tag "application"' all works fine (with no javascript), so something javascript-related is missing.
Showing C:/.../app/views/layouts/application.html.erb where line #7 raised:
couldn't find file 'jquery'
(in C:/.../app/assets/javascripts/application.js:7)
Extracted source (around line #7):
4: <title><%= @title unless @title.blank? %></title>
5: <!-- %= render 'layouts/stylesheets' % -->
6: <%= stylesheet_link_tag "application" %>
7: <%= javascript_include_tag "application", :debug => true %>
8: <%= csrf_meta_tags %>
9: </head>
10: <body>
In my Gemfile I have the entry for jquery-rails:
source 'http://rubygems.org'
gem 'rails', '3.1.0'
gem 'jquery-rails'
....
In application.js:
// This is a manifest file .......
//
//= require jquery
//= require jquery_ujs
//= require_tree .
//
As far as I know that it is the only requirement for working with jQuery in Rails 3.1.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是Rails 3.1中的一个新指令,其中提到了所需的jquery.js文件。
在Rails 3.1中,jquery.js和jquery_ujs.js文件位于jquery-rails gem中包含的vendor/assets/javascripts目录内。
另外,您是否进行了捆绑安装?
有关资产管道的更多信息,请访问 http://guides.rubyonrails.org/asset_pipeline.html。
有关在 Rails 中使用 Javascript 的更多信息,请访问 http://guides.rubyonrails.org/ asset_pipeline.html#manifest-files-and-directives。
Is a new directive in Rails 3.1, which mentions the jquery.js file required.
In Rails 3.1, the jquery.js and jquery_ujs.js files are located inside the vendor/assets/javascripts directory contained within the jquery-rails gem.
Also, did you do a bundle install ?
More about the asset pipeline at http://guides.rubyonrails.org/asset_pipeline.html.
More about using Javascript in Rails at http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives.