Rails 在 .scss 中使用 asset-url 时资产预编译上的 NoMethodError
Rails NoMethodError on Assets Precompile when using asset-url in .scss
我一直在努力解决这个问题,我在我的 .scss
文件中使用 x2 background-image
并从 /assets/images
调用这些图像,但是当我尝试在我的服务器(生产)中预编译它 returns a rake aborted!
root@X:/home/rails/rails_project# RAILS_ENV=production rake assets:precompile
DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.
Please register a mime type using `register_mime_type` then
use `register_compressor` or `register_transformer`.
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in <class:Railtie> at /usr/local/rvm/gems/ruby-2.2.1/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:16)
DEPRECATION WARNING: You are using the a deprecated processor interface Less::Rails::ImportProcessor.
Please update your processor interface:
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in <class:Railtie> at /usr/local/rvm/gems/ruby-2.2.1/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:21)
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/sass_processor.rb:278:in `sprockets_context'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/sass_processor.rb:124:in `asset_path'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/sass_processor.rb:137:in `asset_url'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/script/tree/funcall.rb:143:in `_perform'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/script/tree/node.rb:58:in `perform'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:397:in `visit_prop'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:160:in `block in visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:79:in `block in with_base'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:115:in `with_frame'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:79:in `with_base'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:160:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:433:in `block (2 levels) in visit_rule'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:433:in `map'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:433:in `block in visit_rule'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:181:in `with_environment'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:431:in `visit_rule'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:160:in `block in visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:79:in `block in with_base'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:115:in `with_frame'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:79:in `with_base'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:160:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:52:in `block in visit_children'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:52:in `map'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:52:in `visit_children'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:169:in `block in visit_children'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:181:in `with_environment'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:168:in `visit_children'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `block in visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:188:in `visit_root'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:159:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:8:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/root_node.rb:36:in `css_tree'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/root_node.rb:20:in `render'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/engine.rb:281:in `render'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/sass_compressor.rb:48:in `call'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/sass_compressor.rb:28:in `call'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `call_processors'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in `block in load'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in `load'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `yield'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in `find_asset'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:142:in `block in find'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `logical_paths'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:140:in `find'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in `compile'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
我通过将 background-image: x.jpg;
更改为 background-image: url(image_path("x.jpg"));
来修复此问题发生的事情是它不会预编译图像,因为直到我添加 image_path
告诉 rails 在 assets
.
中查找
我一直在努力解决这个问题,我在我的 .scss
文件中使用 x2 background-image
并从 /assets/images
调用这些图像,但是当我尝试在我的服务器(生产)中预编译它 returns a rake aborted!
root@X:/home/rails/rails_project# RAILS_ENV=production rake assets:precompile
DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.
Please register a mime type using `register_mime_type` then
use `register_compressor` or `register_transformer`.
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in <class:Railtie> at /usr/local/rvm/gems/ruby-2.2.1/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:16)
DEPRECATION WARNING: You are using the a deprecated processor interface Less::Rails::ImportProcessor.
Please update your processor interface:
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in <class:Railtie> at /usr/local/rvm/gems/ruby-2.2.1/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:21)
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/sass_processor.rb:278:in `sprockets_context'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/sass_processor.rb:124:in `asset_path'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/sass_processor.rb:137:in `asset_url'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/script/tree/funcall.rb:143:in `_perform'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/script/tree/node.rb:58:in `perform'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:397:in `visit_prop'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:160:in `block in visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:79:in `block in with_base'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:115:in `with_frame'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:79:in `with_base'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:160:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:433:in `block (2 levels) in visit_rule'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:433:in `map'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:433:in `block in visit_rule'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:181:in `with_environment'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:431:in `visit_rule'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:160:in `block in visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:79:in `block in with_base'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:115:in `with_frame'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/stack.rb:79:in `with_base'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:160:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:52:in `block in visit_children'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:52:in `map'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:52:in `visit_children'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:169:in `block in visit_children'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:181:in `with_environment'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:168:in `visit_children'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `block in visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:188:in `visit_root'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:159:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:8:in `visit'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/root_node.rb:36:in `css_tree'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/tree/root_node.rb:20:in `render'
/usr/local/rvm/gems/ruby-2.2.1/gems/sass-3.4.23/lib/sass/engine.rb:281:in `render'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/sass_compressor.rb:48:in `call'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/sass_compressor.rb:28:in `call'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `call_processors'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in `block in load'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in `load'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `yield'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in `find_asset'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:142:in `block in find'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `logical_paths'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:140:in `find'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in `compile'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/rvm/gems/ruby-2.2.1/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
我通过将 background-image: x.jpg;
更改为 background-image: url(image_path("x.jpg"));
来修复此问题发生的事情是它不会预编译图像,因为直到我添加 image_path
告诉 rails 在 assets
.