I'm trying to set environment variables in Rails. I'm following these docs: http://railsapps.github.io/rails-environment-variables.html
One option it gives is to save environment variables in your ~/.bashrc
, using this syntax:
export GMAIL_USERNAME="[email protected]"
I tried adding exactly this to my ~/.bashrc
. Then I stop my rails server, close my terminal, open my terminal, start rails server. The environment variable still doesn't seem to be available.
I've checked if it is available by doing rails console
in my project root folder, and trying > ENV["GMAIL_USERNAME"] # => outputs nil
How can I set an environment variable locally (in development) so that my Rails project has access to it?
I dont know which shell you are using. In case of bash
, you can write this in your ~/.bashrc
file
export [email protected]
then do this in terminal
source ~/.bashrc
Now, check it console . I am sure it will be there .
Create a new file: config/initializers/settings.rb
GMAIL_USERNAME = case Rails.env
when 'development' then '[email protected]'
end
Restart your app and console.
You should be able to access it wherever you want:
> GMAIL_USERNAME
=> '[email protected]'
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