Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env is not correct when preloading #305

Open
jpalermo opened this issue May 6, 2014 · 1 comment
Open

Env is not correct when preloading #305

jpalermo opened this issue May 6, 2014 · 1 comment
Labels

Comments

@jpalermo
Copy link

jpalermo commented May 6, 2014

When a new Spring::Application is created it calls preload first. However, it does this with the ENV settings from when the Spring server was first started.

This can cause preloading to fail if you are trying to set your database connection string using a DATABASE_URL.

If you first started spring in a RAILS_ENV that did not require DATABASE_URL to be set, because it is in the database.yml file. Then you try to start a console in another RAILS_ENV that requires a DATABASE_URL, the preload fails because it does not have DATABASE_URL set when doing the preload.

@eval
Copy link

eval commented May 7, 2014

Related: #267

As a workaround I added this to config/spring.rb:

Spring.after_fork do
  ActiveRecord::Base.remove_connection
  ActiveRecord::Base.configurations = { Rails.env.to_sym => ENV['DATABASE_URL'] }
  ActiveRecord::Base.establish_connection
end 

YMMV as I use DATABASE_URL for all Rails envs and don't use config/database.yml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants