我正在开发一个 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:
Reservations::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 + 乘客 phusion)时,我得到了相同的错误和相同的跟踪:
`@application.css' is not allowed as an instance variable name
编辑#3:好的,我已经进一步缩小了范围。它肯定与 public/assets/manifest.yml 中的条目有关。我通过删除清单 (application.css) 中的第一个条目来测试这一点,并且错误更改以反映新的第一个条目application.js。仍然是同样的错误,只是使用了一个新的“实例变量”。