链轮未加载清单文件(jQuery,jQuery_ujs)

4
我遇到了一个问题,就是sprockets无法加载"application.js"文件中的清单部分所指定的文件。我尝试重新排列"application.js"文件中的指令,尝试升级和降级Ruby/Rails版本,但都不能让sprockets加载指令中的文件。
我在"assets/javascripts"和"assets/stylesheets"文件夹中添加了一些其他文件,以查看sprockets是否会加载这些文件,但这些文件也没有被加载。然而,如果进入控制台并输入"Sprockets.class",它会识别该模块,因此似乎确实已经加载了sprockets。
我使用的是Ruby 2.0.0/Rails 3.2.8。
以下是我的Gemfile:
source 'https://rubygems.org'

gem 'rails', '3.2.8'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

gem "rspec-rails", :group => [:test, :development]
group :test do
gem "factory_girl_rails"
gem "capybara"
gem "guard-rspec"
gem "debugger"
end

group :assets do
gem 'sass-rails',   '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end

gem "jquery-rails"

这是我的Gemfile.lock文件,其中没有任何与Sprockets或jQuery相关的条目

specs:
actionpack (3.2.1)
  sprockets (~> 2.1.2

sprockets (2.1.3)

jquery-rails (3.0.4)

DEPENDENCIES
  jquery-rails

编辑1 - Application.js

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts,     vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require jquery.cookie
//= require_tree .

$(document).ready(function(){
alert('shit is ready');
});

然后在Chrome控制台中出现错误信息'Uncaught ReferenceError: $ is not defined'。当我使用 'Rails.application.config.assets.paths' 显示我的资源路径时,可以看到jQuery库确实在加载路径中。我还检查了文件是否实际存在于路径中指定的位置,它们确实存在。尝试捆绑项目时,我没有收到任何依赖消息,但我怀疑这就是问题所在。我有很多其他使用Ruby 1.9.2/Rails 3.2.1中jquery/asset pipeline的项目,而我的新设置并没有进行任何不同。我的理解是Sprockets和jQuery都应该无需额外设置即可正常工作,因此我感到特别困惑。谢谢!

你能把你的application.js文件的内容放上来吗? - Althaf Hameez
2个回答

7

0

这是在生产环境吗?请在您的 config/environments/production.rb 中尝试此操作。

config.assets.precompile += ['*.js', '*.css']

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接