【问题标题】:Sprockets not loading manifest files (jQuery, jQuery_ujs)链轮不加载清单文件(jQuery、jQuery_ujs)
【发布时间】:2013-07-24 16:21:54
【问题描述】:

我在让 sprocket 加载“application.js”文件的清单部分中指定的文件时遇到问题。我尝试重新排序“application.js”文件中的指令,我尝试升级和降级 ruby​​/rails,但没有任何东西导致 sprockets 加载指令中的文件。

我在 'assets/javascripts' 和 'assets/stylesheets' 文件夹中添加了一些其他文件,以查看 sprocket 是否会加载这些文件,但也没有一个文件被加载。但是,如果进入控制台并键入“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 管道,而我的新设置没有做任何不同的事情。我的理解是 sprockets 和 jquery 都是开箱即用的东西,所以我特别困惑。

谢谢!!!!

【问题讨论】:

  • 能不能把你的application.js的内容放上去

标签: jquery ruby-on-rails ruby asset-pipeline sprockets


【解决方案1】:

我认为这是因为 sprockets 和 Ruby 2.0 之间的问题。我遇到了同样的问题,请查看:https://github.com/rails/rails/issues/8237 和 https://github.com/sstephenson/sprockets/issues/352。您可以将 rails 更新到 3.2.13,它应该可以工作。

【讨论】:

    【解决方案2】:

    这是在生产环境中吗?在你的 config/environments/production.rb 中试试这个

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

    【讨论】:

      猜你喜欢
      • 2015-08-31
      • 1970-01-01
      • 2012-04-07
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多