4

私は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: OK、これをもう少し絞り込みました。これは間違いなく public/assets/manifest.yml のエントリと関係があります。マニフェスト (application.css) の最初のエントリを削除してこれをテストしたところ、新しい最初のエントリapplication.jsを反映するようにエラーが変更されました。新しい「インスタンス変数」を使用しただけで、同じエラーが発生します。

4

1 に答える 1

1

これはおそらくapplication.cssファイルのせいではありません。問題はpsychにあります。おそらく、public /assets /manifest.ymlの読み込みに問題が発生しているためです。可能な解決策とともに、ブレードコミットでこの同様のエラーを参照してください。

https://github.com/evilchelu/braid/commit/f08fac25570a1a56de8d6282f637d0604ef5e210

精神を取り除いてみてください。それが不可能な場合は、そこで問題を探してください。スタックトレースのこの部分を参照してください。

 psych.rb:205:in `load_file'

あなたがそれを維持したいのであれば、これを修正する精神へのパッチを見つけることができるはずです。

于 2012-08-31T08:10:40.157 に答える