我正在开发一个Rails 3.2应用程序,我正在尝试测试预编译我的资产,以便将我的应用程序投入生产。该应用程序在开发中运行良好,但是当我运行时:
bundle exec rake assets:precompile
我收到以下错误:
rake aborted!
`@application.css' is not allowed as an instance variable name
我搜索了我的代码,并且没有对application.css的引用,当然除了该名称的文件(以及偶尔的注释)。
我也尝试在生产模式下设置config.assets.compile = true
,但也失败了(应用服务器启动正常,但在production.log中没有错误,我只看到请求,Rails渲染一个反应,但没有完成。)
感谢您的帮助。
当我运行bundle exec rake assets:precompile
时,这是一个完整的跟踪:
$ bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/alb64/.rbenv/versions/1.9.2-p320/bin/ruby /Users/alb64/.rbenv/versions/1.9.2-p320/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
rake aborted!
`@application.css' is not allowed as an instance variable name
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:244:in `instance_variable_set'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:244:in `block in init_with'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:244:in `each'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:244:in `init_with'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:229:in `revive'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:183:in `visit_Psych_Nodes_Mapping'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych/visitors/visitor.rb:7:in `accept'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:16:in `accept'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych/nodes/node.rb:25:in `to_ruby'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych.rb:107:in `load'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/psych.rb:205:in `load_file'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/railtie.rb:42:in `block in <class:Railtie>'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `instance_exec'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `run'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/railties-3.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `each'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `run_initializers'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/railties-3.2.0/lib/rails/application.rb:136:in `initialize!'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/railties-3.2.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/alb64/code/stc/reservations/config/environment.rb:6:in `<top (required)>'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `block in require'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/railties-3.2.0/lib/rails/application.rb:103:in `require_environment!'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/railties-3.2.0/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/assets.rake:89:in `block (2 levels) in <top (required)>'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/assets.rake:56:in `block (3 levels) in <top (required)>'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/alb64/.rbenv/versions/1.9.2-p320/bin/rake:23:in `load'
/Users/alb64/.rbenv/versions/1.9.2-p320/bin/rake:23:in `<main>'
Tasks: TOP => environment
rake aborted!
Command failed with status (1): [/Users/alb64/.rbenv/versions/1.9.2-p320/bi...]
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `call'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `sh'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `sh'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:80:in `ruby'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `ruby'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/assets.rake:9:in `ruby_rake_task'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/assets.rake:17:in `invoke_or_reboot_rake_task'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/assets.rake:25:in `block (2 levels) in <top (required)>'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/alb64/.rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/alb64/.rbenv/versions/1.9.2-p320/bin/rake:23:in `load'
/Users/alb64/.rbenv/versions/1.9.2-p320/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile
修改
这是config / environment.rb:
# Load the rails application
require File.expand_path('../application', __FILE__)
require 'rails_extensions'
# Initialize the rails application
Reservations::Application.initialize!
这是config / environments / production.rb:
预订:: Application.configure do #此处指定的设置将优先于config / application.rb
中的设置 # The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile"
# For nginx:
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# If you have no front-end server that supports something like X-Sendfile,
# just comment this out and Rails will serve the files
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Disable Rails's static asset server
# In production, Apache or nginx will already do this
config.serve_static_assets = false
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Compress JavaScripts and CSS
config.assets.compress = true
# Choose the compressors to use
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :yui
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# Defaults to Rails.root.join("public/assets")
# config.assets.manifest = YOUR_PATH
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
end
编辑#2:所以我将config.assets.digest更改为false,现在rake assets:precompile
运行正常,但是当我去启动服务器时(nginx +乘客错误) )我得到相同的错误相同的错误:
`@application.css' is not allowed as an instance variable name
编辑#3:好的,我把它缩小了一点。它肯定与public / assets / manifest.yml中的条目有关。我通过删除清单(application.css)中的第一个条目对此进行了测试,并且错误发生变化以反映 new 第一个条目 application.js 。仍然是同样的错误,只是使用新的'实例变量'。
答案 0 :(得分:1)
这可能不是您的application.css文件的错误。问题在于心理问题,可能是因为它导致加载public / assets / manifest.yml时遇到问题,在编码提交中看到这个类似的错误,并提供了一个可能的解决方案:
https://github.com/evilchelu/braid/commit/f08fac25570a1a56de8d6282f637d0604ef5e210
尝试删除心理,或者如果不可能,请在那里寻找问题。查看堆栈跟踪的这一部分:
psych.rb:205:in `load_file'
你应该能找到一个心理补丁,如果你想保留它就会解决这个问题。