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.
Use command ENV in rails console. That will return a hash of your environmental values you can access. Alternatively, you can access your environmental variables from your apps root path using the same command and the variables will be returned formatted.
Ruby has direct access to environment variables via the ENV hash. Environment variables can be directly read or written to by using the index operator with a string argument. Note that writing to environment variables will only have an effect on child processes of the Ruby script.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With