1

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

6
  • 1
    Please make sure that you have put the env.rb file in initializers folder. Commented Apr 1, 2013 at 12:09
  • i put my env.rb file in the config folder, is this not correct? Commented Apr 1, 2013 at 13:49
  • No. You should put env.rb file in initializers folder. Commented Apr 1, 2013 at 14:00
  • then i guess add that to the gitignore file aswell? Commented Apr 1, 2013 at 14:05
  • It's upto your requirements. If you don't want to push the file to heroku then you should add it to .gitignore file. Commented Apr 1, 2013 at 14:07

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.