Ticker

6/recent/ticker-posts

Config in rails

For general application configuration that doesn't need to be stored in a database table, I like to create a config.yml file within the config directory. For your example, it might look like this:

defaults: &defaults
  audiocast_uri_format: http://blablalba/blabbitybla/yadda

development:
  <<: *defaults

test:
  <<: *defaults

production:
  <<: *defaults
This configuration file gets loaded from a custom initializer in config/initializers:

APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV]
You can then retrieve the value using:

uri_format = APP_CONFIG['audiocast_uri_format']


--
Regards,
Pavan

Post a Comment

0 Comments