Rails : Loading configuration from custom yml file

01 Jun 2012


Recently while I was working on a rails project I need to use a lot of custom project configurations. when I checked on web I found rails_config gem. But my colleague, proposed me another easy way to do it. Since I just need to load all the configs as an hash to a variable, I don't really need rails_config.

  1. create config.yml in config/ folder

    Here is sample config.yml
    Here I just defined the separate config for each envirnment, which is easy to maintain later.
  2. create config.rb in config/initializers/ folder with below content


Now we can use CONFIG variable in any where in the project. We can get the configuration of foo as CONFIG["foo"]
Thank You Happy Coding ;)
If you particularly enjoy my work, I appreciate donations given with Gittip.
comments powered by Disqus