我有一个奇怪的情况,突然面临编译前的失败,老实说,由于某些原因,我无法看到这个问题。
我在这里添加了一个带有日志和参考文件的要点 https://gist.github.com/malagodia/8506722
令我困惑的是,我阅读了有关数据库连接的Heroku建议,并明确确保application.rb包含
config.assets.initialize_on_precompile = false
这是日志输出错误,完整登录要点
Running: rake assets:precompile
rake aborted!
undefined method `[]=' for nil:NilClass
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/config/initializers/database_connection.rb:7:in `block (2 levels) in <top (required)>'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:27:in `each'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/config/initializers/database_connection.rb:5:in `block in <top (required)>'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:36:in `call'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `each'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/config/environment.rb:5:in `<top (required)>'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/application.rb:189:in `require_environment!'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/application.rb:250:in `block in run_tasks_blocks'
/tmp/build_2826537d-5a5c-43f7-b792-45112618d3df/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:54:in `block (2 levels) in define'
Tasks: TOP => environment
(See full trace by running task with --trace) ! ! Precompiling assets failed. !
! Push rejected, failed to compile Ruby app
追踪追踪heroku指出
〜$ rake assets:precompile --trace
**调用资产:预编译(first_time)
**调用资产:环境(first_time)
**执行资产:环境
**调用环境(first_time)
**执行环境
**执行资产:预编译
答案 0 :(得分:1)
从Rails 4升级到4.1时,我最近遇到了这个问题。
为了解决这个问题,我刚删除了文件database_connection.rb
。我有这个文件是因为Heroku的文章是Concurrency and Database Connections in Ruby with ActiveRecord。
我希望它有所帮助!
答案 1 :(得分:0)
我相信您的config
值为nil
,因为您预编译资产时数据库(或环境中的任何其他内容)不可用,因此您应该尽力避免任何事情与该阶段的数据库相关。情况描述为here。
他们描述的解决方案只是“不要那样做”:
“一旦隔离了错误,就必须通过不依赖于环境变量和数据库在预编译时出现来修复错误。”
答案 2 :(得分:0)
我的情况,我忘了更新application.css的扩展名以包含.scss。所以,我猜测,sprockets试图编译一个不存在的.scss文件;因此没有错误。
我通过运行&#34; RAILS_ENV =生产包exec rake资产来识别错误:预编译&#34;在本地但在生产环境中编译我的资产(根据Heroku文档:https://devcenter.heroku.com/articles/rails-asset-pipeline)并查看最后几行输出(输出比将整个应用程序推送到Heroku更清洁,更快):
NoMethodError:未定义的方法`[]&#39;为零:NilClass (在/other_stuff/my_app/app/assets/stylesheets/application.css中)
我注意到了.css扩展名并添加了.scss来修复错误。