I'm aware that there are some other questions related to this issue, but I haven't been able to find an answer yet.
I'm building an app with Rails 4.1.4. I'm using MongoDB as my database and Mongoid 4.0.0 as ODM.
When I push my app to Heroku, the build fails when running rake assets:precompile because Rails tries to connect to the production database, which is not initialized at this point, and defaults connecting to the development database, which does not exist in production. This is the error I get:
Preparing app for Rails asset pipeline Running: rake assets:precompile rake aborted! Mongo::ConnectionFailure: Failed to connect to a master node at localhost:27017 /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/mongo-1.10.2/lib/mongo/mongo_client.rb:422:in
connect' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/mongo-1.10.2/lib/mongo/mongo_client.rb:661:in
setup' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/mongo-1.10.2/lib/mongo/mongo_client.rb:177:ininitialize' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/mongo_mapper-0.13.0/lib/mongo_mapper/connection.rb:88:in
new' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/mongo_mapper-0.13.0/lib/mongo_mapper/connection.rb:88:inconnect' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/mongo_mapper-0.13.0/lib/mongo_mapper/connection.rb:98:in
setup' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/mongo_mapper-0.13.0/lib/mongo_mapper/railtie.rb:48:inblock in <class:Railtie>' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in
instance_exec' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:inrun' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/initializable.rb:55:in
block in run_initializers' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/initializable.rb:54:inrun_initializers' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/application.rb:300:in
initialize!' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/config/environment.rb:5:in<top (required)>' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/application.rb:276:in
require' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/application.rb:276:inrequire_environment!' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/application.rb:379:in
block in run_tasks_blocks' /tmp/build_f8b818f9-3058-4ea1-807e-158e2964efcd/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.1.4/lib/sprockets/rails/task.rb:64: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
Does anyone knows a fix for this issue?. How can I tell Rails to not connect to the databse while precompiling assets in the production environment?.
Thanks in advance for any help!.
Best,