jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Sprockets没有加载清单文件(jQuery,jQuery_ujs)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个问题,让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"

这是我的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管道的项目,而且我的新设置没有做任何不同的事情.我的理解是链轮和jquery都是开箱即用的东西所以我特别困惑.

谢谢!!!!

解决方法

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

大佬总结

以上是大佬教程为你收集整理的Sprockets没有加载清单文件(jQuery,jQuery_ujs)全部内容,希望文章能够帮你解决Sprockets没有加载清单文件(jQuery,jQuery_ujs)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。