Richlewis
Richlewis

Reputation: 15384

Making ENV variables accessible in development

When storing sensitive credentials I normally create a yml file and load it like so in my development.rb

APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env]

I can then access like so

APP_CONFIG["google_secret"]

Problem is Heroku doesn't like this so i need to set ENV variables locally to make integration easier. so i have created a env.rb file like so

ENV['google_key'] = 'xxx'
ENV['google_secret'] = 'xxx'
ENV['application_key'] = 'xxx'

and to accesss it i thought i could use

x = ENV['application_key']

But its not finding the variable, how do I load them in the development environment?

Thanks

Upvotes: 1

Views: 937

Answers (2)

Kashif Umair Liaqat
Kashif Umair Liaqat

Reputation: 1074

You should put the env.rb file in initializers folder. You can add env.rb file to .gitignore file if you don't want to push it to heroku.

Upvotes: 3

Paul Fioravanti
Paul Fioravanti

Reputation: 16793

Have you considered using Figaro to do this? Figaro was inspired by Heroku's secret key application configuration, so it's really easy to make secret ENV variables in development accessible in Heroku production environments.

I wrote up an answer on this StackOverflow thread about hiding secret info in Rails (using Figaro) that can hopefully serve of some reference to you as well.

Upvotes: 2

Related Questions