rails 4.2 assets预编译问题

rails 4.2 assets precompilation issue

我正在测试 RoR 4 的部署。2.x 应用程序...

当我在开发中执行它时,一切 运行 都很好, 如果我在虚拟机上模拟部署以准备最终部署阶段, 我在资产预编译期间收到错误....

部署环境是 ubuntu 14.04 lts 服务器,使用 rvm、passenger 和 Apache 作为网络服务器..

在完成所有需要的库更新(作为先决条件)之后,我已经将 repo 检出到 Web 服务器上的工作目录, 然后在工作目录中正确执行 'bundle update' 以正确填充 gemset...

在此阶段,服务器控制台未返回任何错误,似乎一切正常 运行...

if i 运行 'gem list' 所有需要的宝石结果都存在

现在,使用命令预编译资产:

RAILS_ENV=production bundle exec rake assets:precompile

操作在几秒后中止并出现此错误:

rake aborted!
Sprockets::FileNotFound: couldn't find file 'jquery-ui' with type 'application/javascript'
/home/rails-usr/www_v2/app/assets/javascripts/application.js:10
/home/rails-usr/.rvm/gems/ruby-2.2.2@Best-i-gest_v2/gems/sprockets-3.6.2/lib/sprockets/resolve.rb:64:in `resolve!'
/home/rails-usr/.rvm/gems/ruby-2.2.2@Best-i-gest_v2/gems/sprockets-3.6.2/lib/sprockets/directive_processor.rb:399:in `resolve'
/home/rails-usr/.rvm/gems/ruby-2.2.2@Best-i-gest_v2/gems/sprockets-3.6.2/lib/sprockets/directive_processor.rb:207:in `process_require_directive'
.....

要为我的问题添加更多信息...

这是我的应用程序 'Gemfile'

source 'http://rubygems.org'

gem 'rails', '4.2.5'

gem 'mysql2', '0.3.17'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'declarative_authorization', :git => 'git://github.com/stffn/declarative_authorization'
gem 'ruby_parser'
gem 'jQuery-Validation-Engine-rails'
gem 'prawn', '1.3.0'
gem 'prawn-table', '0.2.1'

# gem 'bootstrap-sass', '~> 3.1.1'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier'

  gem "therubyracer"
  gem "less-rails", :git => 'git://github.com/metaskills/less-rails', :ref => '539f28d'

  gem 'jquery-datatables-rails' , :git => 'git://github.com/rweng/jquery-datatables-rails'
  gem 'jquery-ui-rails'
end

gem 'twitter-bootstrap-rails', :git => 'git://github.com/coppolaf/tb3-rails4.git'

gem 'jquery-rails'
gem 'will_paginate'
gem 'nokogiri'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :test do
  # Pretty printed test output
  gem 'turn', '~> 0.8.3', :require => false
end

这是 'application.js' 文件:

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require twitter/bootstrap
//= require jquery.validationEngine
//= require_tree .
....

这是 'application.css' 文件:

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require jquery-ui
 *= require dataTables/src/demo_table_jui
 *= bootstrap_and_overrides.css.less
 *= require validationEngine.jquery
 *= require_tree .
 */
....

请注意所有 jquery 模块 运行 正在开发中,请求的模块似乎存在于 gemset 中....

等待您的建议,

此致, 弗朗切斯科

根据您发布的 sprockets 错误,我认为您的 application.js

中缺少这一行
//= require jquery-ui

Documentation

已添加

您的补充信息很有帮助。 你的 application.css 不应该包括 jquery-ui,这不是 css 并且会抛出一个与你的一致的链轮错误重新看到。我会减少您的 application.css 以仅包含 css 类型的资产。

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 *= require_tree .
 *= bootstrap_and_overrides.css.less
 *= any other css, scss, etc
 *= require_self
  */

让我知道这是怎么回事。


建议测试

我刚刚注意到开发和生产之间存在差异。在您的 jquery-ui 设置中。这是一个重要的测试,因为它是您看到的资产负载问题。这就是你所拥有的:

group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier'

  gem "therubyracer"
  gem "less-rails", :git => 'git://github.com/metaskills/less-rails', :ref => '539f28d'

  gem 'jquery-datatables-rails' , :git => 'git://github.com/rweng/jquery-datatables-rails'
  gem 'jquery-ui-rails'
end

尝试将 gem 移动到 Gemfile 中的资产组 之外,如下所示,然后 $bundle install 和测试:

gem 'jquery-rails'
gem 'jquery-ui-rails'

让我知道发生了什么

感谢Wishalizer的建议,我终于解决了这个问题...

错误与Gemfile结构有关....我修改如下......

文件:'Gemfile'

source 'http://rubygems.org'

gem 'rails', '4.2.5'

gem 'mysql2', '0.3.17'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'declarative_authorization', :git => 'git://github.com/stffn/declarative_authorization'
gem 'ruby_parser'
gem 'jQuery-Validation-Engine-rails'
gem 'prawn', '1.3.0'
gem 'prawn-table', '0.2.1'

# gem 'bootstrap-sass', '~> 3.1.1'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier'

  gem "therubyracer"
  gem "less-rails", :git => 'git://github.com/metaskills/less-rails', :ref => '539f28d'

end

gem 'twitter-bootstrap-rails', :git => 'git://github.com/coppolaf/tb3-rails4.git'

gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'jquery-datatables-rails' , :git => 'git://github.com/rweng/jquery-datatables-rails'
gem 'will_paginate'
gem 'nokogiri'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :test do
  # Pretty printed test output
  gem 'turn', '~> 0.8.3', :require => false
end

将对 jquery-ui-rails 和 jquery-datatables-rails 的引用移到资产部分之外... 使资产预编译任务无错完成!!

希望这对您有所帮助....

再见 弗朗切斯科