How to load environment variables in the Rails console?

M.ElSaka picture M.ElSaka · Mar 12, 2013 · Viewed 8.4k times · Source

I think this is a little, easy question!

I'm using .env file to keep all my environment variables, and i'm using foreman.

Unfortunately, these environment variables are not being loaded when running rails console rails c so, i'm now loading them manually after running the console, which is not the best way.

I'd like to know if there any better way for that.

Answer

dquimper picture dquimper · Jun 10, 2013

About a year ago, the "run" command was added to foreman

ref: https://github.com/ddollar/foreman/pull/121

You can use it as follow:

foreman run rails console

or

foreman run rake db:migrate