1

I need to create a custom config in my app rails to load the configuration url of my services and accessing the configuration in my models.

Thank you.

  • http://stackoverflow.com/questions/592554/best-way-to-create-custom-config-options-for-my-rails-app – Jordi Mar 13 '12 at 13:31

1 Answers1

1

Create the file you need in your config directory, for example my_config.yml and populate it with the options you require per environment:

development:
  debug_enabled: true

test:
  debug_enabled: false

production:
  debug_enabled: false

Then create a file called load_config.rb in your config/initializers directory with this in it:

MY_CONFIG = YAML.load_file("#{Rails.root}/config/my_config.yml")[Rails.env]

Then you can use those settings in your applications like so:

if MY_CONFIG[:debug_enabled]
  # ... do something special ...
end
Jon
  • 10,678
  • 2
  • 36
  • 48