Rails_admin 为生产预编译资产失败:未定义的混合

Rails_admin fails in precompiling assets for production: Undefined mixin

正在尝试预编译我的应用程序资产,但 rails_admin 失败。

这是日志:

Farhans-MacBook-Pro:gmanga farhan$ RAILS_ENV=production bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
rake aborted!
Sass::SyntaxError: Undefined mixin 'opacity'.
  (in /Users/farhan/gmanga/vendor/bundle/gems/rails_admin-0.6.7/app/assets/stylesheets/rails_admin/base/theming.scss:244)
/Users/farhan/gmanga/vendor/bundle/gems/rails_admin-0.6.7/app/assets/stylesheets/rails_admin/base/theming.scss:244:in `opacity'
/Users/farhan/gmanga/vendor/bundle/gems/rails_admin-0.6.7/app/assets/stylesheets/rails_admin/base/theming.scss:244
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:253:in `visit_mixin'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:100:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `map'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `block in visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:320:in `visit_rule'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:100:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `map'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `block in visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:320:in `visit_rule'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:100:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `map'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `block in visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:320:in `visit_rule'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:100:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `map'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `block in visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:320:in `visit_rule'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:100:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `map'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:53:in `visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `block in visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:128:in `visit_root'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:100:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:7:in `visit'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/tree/root_node.rb:20:in `render'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/engine.rb:315:in `_render'
/Users/farhan/gmanga/vendor/bundle/gems/sass-3.2.19/lib/sass/engine.rb:262:in `render'
/Users/farhan/gmanga/vendor/bundle/gems/sass-rails-4.0.5/lib/sass/rails/template.rb:22:in `evaluate'
/Users/farhan/gmanga/vendor/bundle/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/context.rb:197:in `block in evaluate'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `each'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `evaluate'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `new'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/base.rb:373:in `build_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/bundled_asset.rb:37:in `init_with'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/asset.rb:24:in `from_hash'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/caching.rb:54:in `cache_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:211:in `block in find_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:257:in `benchmark'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:210:in `find_asset'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:119:in `block in compile'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:118:in `each'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:118:in `compile'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-rails-2.2.4/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-2.12.3/lib/rake/sprocketstask.rb:146:in `with_logger'
/Users/farhan/gmanga/vendor/bundle/gems/sprockets-rails-2.2.4/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/farhan/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/Users/farhan/gmanga/vendor/bundle/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/Users/farhan/gmanga/vendor/bundle/bin/rake:23:in `load'
/Users/farhan/gmanga/vendor/bundle/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile

我的 Gemfile:

source 'https://rubygems.org'
# gem 'sinatra', '1.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

gem 'devise'
gem 'rails_admin'#, :github => 'sferik/rails_admin'
# gem 'bootstrap-sass', '~> 3.3.4'

gem 'recaptcha', :require => 'recaptcha/rails'
gem 'rack-cors', :require => 'rack/cors'
gem "mechanize"
gem 'mercury-rails', :git => 'git://github.com/jejacks0n/mercury.git'
gem 'carrierwave'
gem 'mini_magick'
gem 'fog'
gem 'rails_emoji', '~> 1.7.1'
gem 'rubyzip'
gem 'aws-sdk', '< 2.0'

gem 'uuid', '~> 2.3.7'
gem 'friendly_id', '~> 5.0.0'
gem 'mailboxer', :git => 'git://github.com/div/mailboxer.git', :branch => 'rails42-foreigner'
gem 's3_direct_upload'
gem 'rails_autolink'
gem 'will_paginate', '~> 3.0'
gem 'will_paginate-bootstrap'
gem 'unicorn'
gem 'unicorn-worker-killer'
gem 'naturally', '1.3.1'
gem 'ransack'
gem 'dalli'
# gem 'libarchive-static', '~> 1.0.3'

# gem 'seven_zip_ruby', '~> 1.2.3'
# gem 'aws-s3', '0.6.2', :require => 'aws/s3'
gem 'zip-zip' # will load compatibility for old rubyzip API.

gem 'whenever', :require => false

gem 'capybara'

gem "browser"
# gem "mini_magick"
# gem 'rmagick'
# gem 'asset_sync'

gem 'image_optim'
gem 'image_optim_pack'

# gem 'sinatra', require: false
gem 'sinatra', '~> 1.4.5'
gem 'slim'
gem 'sidekiq'
# gem 'sinatra'
# gem 'slim'


# gem 'selenium-webdriver'
gem 'poltergeist'
gem 'phantomjs', :require => 'phantomjs/poltergeist'
group :production do
  gem 'rails_12factor'
  gem 'heroku_rails_deflate'
end

group :development, :test, :staging do
  gem 'better_errors'
  gem 'binding_of_caller'
  # gem 'quiet_assets'
  gem 'rack-mini-profiler'
  gem 'bullet'
  # Use Uglifier as compressor for JavaScript assets
  gem 'uglifier', '>= 1.3.0'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

所以我没有使用任何 Twitter bootstrap 资产管道来导致 this page 中提到的这个问题。

我认为 "rails_admin.scss.erb" 由于某些原因没有被包括在内。我用的是 rails_admin 0.6.7,我什至用 rails g rails_admin:install

试过

有什么想法吗?

我找到问题了。这是由您的 config/initializers/assets.rb 中不正确的通配符预编译设置引起的,如下所示:

Rails.application.config.assets.precompile += %w( *.js )

因此,仅指定 .js 您需要显式包含在视图中的文件而不是使用通配符可以解决问题。

我也这样做是为了让 CSS 正常工作:

Rails.application.config.assets.precompile += %w( rails_admin/rails_admin.css 
rails_admin/rails_admin.js )