Recently I worked on a project where I needed certain config variables for staging, production, test etc and I wanted to store all these in a yaml file. I could set them in the different environments files but I prefer them all in one file.

Create a file in the config/initializers .. I called it 00_load_app_config.rb so I can be sure it gets loaded first. In it I have only a single line

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

Then I create a yaml config file at config/app_config.yml

RUBY:
  1. base: &common
  2.     company_name: 'The Awesomest Company Evar!'
  3.     api_username: 'api_user'
  4.     api_password: 'bob123'
  5.  
  6. development:
  7.     <<: *common
  8.     api_hostname: 'http://api-development.myawesomesite.com'
  9.     twitter_app_key: 'fff'
  10.     twitter_app_secret: 'fff'
  11.  
  12. staging:
  13.     <<: *common
  14.     api_hostname: 'http://staging-api.myawesomesite.com'
  15.     twitter_app_key: 'sss'
  16.     twitter_app_secret: 'sss'
  17.  
  18. test:
  19.     <<: *common
  20.     api_hostname:  'http://test-api.myawesomesite.com'
  21.     twitter_app_key: 'eee'
  22.     twitter_app_secret: 'eee'
  23.  
  24. production:
  25.     <<: *common
  26.     api_username: 'api_user_prod'
  27.     api_password: 'bobprod123'
  28.     api_hostname: 'http://production-api.myawesomesite.com'
  29.     twitter_app_key: 'yyy'
  30.     twitter_app_secret: 'yyy'

The variables in the common section are applied to every environment and overridden like in the case of production, which overrides the api_username and api_password. In each environment they pull the company_name from the common block.

To use a value in your rails app, use the APP_CONFIG array, like
APP_CONFIG['website_name'] or APP_CONFIG['twitter_app_key'] and it will always return the value for the environment currently in Rails.env

Thanks to my friend Rath who showed me this, I changed the name from config to app_config because I liked it to be more specific, but use whatever name you like!