Question

I am using RVM with Foreman with Rails 3.2. I have an .env file in my app root directory, which was supposed to be loaded with Foreman. But apparently it couldn't load rails when I use ENV['DATABASE_NAME'] in database.yml. But strangely, after rails is loaded using hardcoded database name, I could open up console and access the ENV['DATABASE_NAME']. And Foreman really can't access ENV in its Procfile either. I have another rails 4 app that could access ENV in devise.rb, which is one of the initializer, but when I put the same ENV['DATABASE_NAME'] in database.yml, it will start the server ok, but not able to open a page when the app is trying to access the database. So it looks like the ENV is only loaded by rails, after rails itself is loaded. How do you allow it also be accessible by Procfile and database.yml.

Was it helpful?

Solution

If you show examples of your Profile and .env it would be be easier for someone to help out.

My wild guess from your question is you are using the env variables incorrectly in the Procfile.

If for example in .env you have PORT=3000

then in your Profile it's referred to as $PORT -- not as ENV['PORT']

In a ruby file such as a config initializer you WOULD use ENV['FOO']

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top