Rails snippet: Storing ENV keys in config

These are pretty much the exact steps from Paul Elliot’s blog post on the subject.

In case you found this post from google, his blog post is a better source for this sort of information than mine, so please look at his post. I’m just repeating the steps here because I keep looking it up and having it on my blog will save me a step.

Put this in config/environments/development.rb

config.before_initialize do
  dev = File.join(Rails.root, 'config', 'development.yml')
  YAML.load(File.open(dev)).each do |key, value|
    ENV[key.to_s] = value
  end if File.exists?(dev)
 Add this in config/development.yml
AWS_KEY: big long key
AWS_SECRET_KEY: another big long key

Add config/development.yml to your .gitignore file.

Someone mentioned a “rails_config” gem in the comments, but I haven’t used or looked into that.

Comments are closed.