lou*_*sm2 4 ruby jquery ruby-on-rails sprockets asset-pipeline
我有一个问题,让sprockets加载'application.js'文件的manifest部分中指定的文件.我已经尝试在'application.js'文件中重新排序指令,我尝试升级和降级ruby/rails,但没有任何东西导致sprockets加载指令中的文件.
我在"assets/javascripts"和"assets/stylesheets"文件夹中添加了一些其他文件,以查看sprockets是否会加载这些文件,但这些文件都没有加载.但是,如果进入控制台并键入"Sprockets.class",它会识别模块,因此似乎确实正在加载链轮.
我使用的是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"
Run Code Online (Sandbox Code Playgroud)
这是我的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
Run Code Online (Sandbox Code Playgroud)
编辑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');
});
Run Code Online (Sandbox Code Playgroud)
然后在chrome控制台中我得到'Uncaught ReferenceError:$ is not defined'
当我使用'Rails.application.config.assets.paths'显示我的资产路径时,我可以看到jQuery库确实在加载路径中.我还检查过以确保文件实际上位于路径中指定的位置.
在尝试捆绑我的项目时,我没有得到任何类型的依赖性消息,但我怀疑这是正在发生的事情.我在Ruby 1.9.2/Rails 3.2.1中有很多其他使用jquery/asset管道的项目,而且我的新设置没有做任何不同的事情.我的理解是链轮和jquery都是开箱即用的东西所以我特别困惑.
谢谢!!!!
我认为这是因为sprockets和Ruby 2.0之间的问题.我遇到了同样的问题,请查看:https://github.com/rails/rails/issues/8237和https://github.com/sstephenson/sprockets/issues/352.您可以将rails更新到3.2.13,它应该可以工作.
| 归档时间: |
|
| 查看次数: |
2275 次 |
| 最近记录: |