Skip to content
maccman edited this page Sep 13, 2010 · 3 revisions

AppConfig is a class which has attributes loaded automatically from the config/application.yml file.

If you add your own key/value pairs to application.yml, then you can just call the key as a method on AppConfig.

For example:

Inside config/application.yml:
app_site: http://example.com

AppConfig.app_site #=> "http://example.com"

You can also call the method with a question mark, if you don’t want a method_missing error if the config value is not set.

Setting configuration variables.

As well as reading configuration variables, you can set them. When the app closes down, the data is marshalled to disk – and reloaded whenever the app starts up again. For example:

AppConfig.app_site = "http://google.com"
AppConfig.app_site #=> "http://google.com"

So, in the above example, app_site has been overridden – and now will always return “http://google.com”.