ruby on rails升级资产预编译失败

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby on rails升级资产预编译失败相关的知识,希望对你有一定的参考价值。

我有一个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中。

答案

很难说在不了解更多配置的情况下发生了什么,但这可能是一个加载问题。 jquery-rails将实际的.js文件放在vendor/assets/javascripts中,无论出于何种原因,这些文件可能不在您的加载路径中。您可以尝试两件事:

首先尝试运行gem附带的生成器,看它是否修复了manifest文件中的路径:

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

如果我是你,我会升级

以上是关于ruby on rails升级资产预编译失败的主要内容,如果未能解决你的问题,请参考以下文章

远程:!预编译资产失败。在heroku上(Rails 6和语义UI)

ruby Rails 4/5通过资产预编译测试加速

ruby 调试rails资产管道js使用uglifier预编译错误

ruby 使用Capistrano 3和rsync进行本地Rails 4资产预编译

RAILS 轨道资产:预编译失败

推送到 heroku 时出现“预编译资产失败”错误