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
Then I create a yaml config file at config/app_config.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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
It will 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!