YAML Configuration File

Blog ยป YAML Configuration File

Posted on 09 Jul 2009 10:22

In Ruby on Rails, you can create application specific configuration files. Put in "config/initializers/myapp.rb"

MYAPP_CONFIG=YAML::load( ERB.new( IO.read( "#{RAILS_ROOT}/config/myapp.yml" ) ).result )[RAILS_ENV].symbolize_keys

In "config/myapp.ytml"

    mode: development
    mode: test
    mode: production

You can access MYAPP_CONFIG throughout the application:

MYAPP_CONFIG[:mode] #=> 'development'

If you like this page, please spread the word: diggdel.icio.usFacebook

You can contact me if you have questions or corrections.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License