Here's how I set my ENV variable
#~/repos/project
export GA_USERNAME="[email protected]"
When I try to use ENV['GA_USERNAME] in my application, it returns nil. However, in the console it strangely prints the variable and then returns nil...
1.9.2-p320 :003 > puts ENV['GA_USERNAME']
[email protected]
=> nil
Edit I don't think my ENV variables are persisting. When I restart my computer, variable is nil and needs to be set again.
A traditional way to set env vars for a server process is:
RAILS_ENV=production GA_USERNAME=foobar rails s
If you want to specify the env vars in a persistent way, like in a file, try figaro. The README tells you how to start, but the idea is:
rails generate figaro:installconfig/application.yml (which the last command created)UPDATE
dotenv might be an even better and simpler approach:
gem 'dotenv-rails', :groups => [:development, :test].env.env.test or .env.developmentSee their README for all the details.
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