0
votes

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:in initialize' /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:in connect' /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:in block 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:in run' /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:in run_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:in require_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,

2

2 Answers

0
votes

You may want to try enabling the labs feature to have the environment available on precompile:

heroku labs:enable user-env-compile

Others seem to be having success doing that in similar situations.

0
votes

ISSUE SOLVED. Rails 4.1.4 has no problem with what I've stated. I was doing something wrong, my bad!.

Regards,