我有一个rails 4.2应用程序我正在从3.2升级。资产预先设定出现了问题,但我不确定我缺少什么。
#Gemfile
gem 'rails', '~> 4.2.7.1'
ruby "2.3.3"
gem 'jquery-rails', '2.1.4'
gem 'jquery-ui-rails', '4.2.1'
gem 'activeadmin'
gem 'sprockets-rails', '2.3.3
这是active_admin.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require select2
//= require active_admin/base
//= require best_in_place
//= require best_in_place.jquery-ui
//= require activeadmin-sortable
资产预编译在这里失败
$ bundle exec rake assets:precompile
I, [2018-02-28T10:58:20.467128 #6312] INFO -- : Writing /home/nellis/src/circle2/public/assets/style-6150d2089bcada194fcfda8d38d0046cadfe7a754b6b477226d1b701cda7e197.css.gz
rake aborted!
Sprockets::FileNotFound: couldn't find file 'jquery_ujs' with type 'application/javascript'
Checked in these paths:
/home/nellis/src/circle2/app/assets/fonts
/home/nellis/src/circle2/app/assets/images
/home/nellis/src/circle2/app/assets/javascripts
/home/nellis/src/circle2/app/assets/stylesheets
/home/nellis/src/circle2/vendor/assets/javascripts
/home/nellis/src/circle2/vendor/assets/stylesheets
/home/nellis/src/circle2/public/vendor
/home/nellis/src/circle2/app/assets/javascripts/active_admin.js:2
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/resolve.rb:65:in `resolve!'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/directive_processor.rb:399:in `resolve'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/directive_processor.rb:207:in `process_require_directive'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/directive_processor.rb:180:in `block in process_directives'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/directive_processor.rb:178:in `each'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/directive_processor.rb:178:in `process_directives'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/directive_processor.rb:83:in `_call'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/directive_processor.rb:68:in `call'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `call_processors'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in `block in load'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in `load'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/bundle.rb:23:in `block in call'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/utils.rb:200:in `dfs'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/bundle.rb:24:in `call'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `call_processors'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in `block in load'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in `load'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in `find_asset'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:134:in `block in find'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:133:in `each'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:133:in `find'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in `compile'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in `with_logger'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
/home/nellis/.rvm/gems/ruby-2.3.3/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/home/nellis/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in `eval'
/home/nellis/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
zlib(finalizer): Zlib::GzipWriter object must be closed explicitly.
zlib(finalizer): the stream was freed prematurely.
我读到的所有问题都说运行bundle install并确保gem文件位于你的Gemfile中。
答案 0 :(得分:1)
如果不了解有关配置的更多内容,很难说明发生了什么,但这可能是一个加载问题。 jquery-rails
将实际的.js
文件放在vendor/assets/javascripts
中,无论出于何种原因,这些文件可能不在您的加载路径中。您可以尝试两件事:
首先尝试运行gem附带的生成器,看看它是否修复了清单文件中的路径:
rails generate jquery:install #--ui to enable jQuery UI
如果这不起作用,并且不想升级jquery-rails
,则可能需要执行此类操作
//= require vendor/assets/javascripts/jquery.js
//= require vendor/assets/javascripts/jquery_ujs.js
//= require vendor/assets/javascripts/jquery-ui.js
如果我是你,我会升级