Reputation: 17
I have a bizarre situation of suddenly being faced with a pre-compile failure and I honestly cannot see the issue for some reason.
I have added a gist with the log and reference files here https://gist.github.com/malagodia/8506722
What confuses me is that I read Heroku recommendations around database connections and have explicitly made sure that application.rb contains
config.assets.initialize_on_precompile = false
Here is the log output error, full log on the gist
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
Additional trace heroku pointed out
~ $ rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
Upvotes: 1
Views: 505
Reputation: 951
Im my case, I forgot to update the extension of my application.css to include .scss. So, I'm guessing, sprockets was trying to compile a .scss file that did not exist; hence the nil error.
I identified the error by running "RAILS_ENV=production bundle exec rake assets:precompile" to compile my assets locally but in the production environment (as per Heroku documentation: https://devcenter.heroku.com/articles/rails-asset-pipeline) and by looking at the last couple lines of output (the output is a little cleaner and quicker than pushing the full app to Heroku):
NoMethodError: undefined method `[]' for nil:NilClass (in /other_stuff/my_app/app/assets/stylesheets/application.css)
I noticed the .css extension and added .scss to fix the error.
Upvotes: 0
Reputation: 1004
I recently had this problem while upgrading from Rails 4 to 4.1.
To solve it I just removed the file database_connection.rb
. I've had this file because of a Heroku's article on Concurrency and Database Connections in Ruby with ActiveRecord.
I hope it helps!
Upvotes: 1
Reputation: 30310
I believe your config
value is nil
because the database (or anything else in the environment) isn't available at the time you precompile your assets, so you should do your best to avoid anything related to a database at that stage. The situation is described here.
And the solution they describe is simply "Don't do that":
"Once you’ve isolated the error, you must fix it by not relying on environment variables and the database to be present at precompile time."
Upvotes: 0