Skip to content

Instantly share code, notes, and snippets.

@ziadoz ziadoz/config.yml
Created Jun 18, 2012

Embed
What would you like to do?
Rails 3 YAML Configuration Loader
# config/config.yml
defaults: &defaults
key: value
regexp: !ruby/regexp /pattern/
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
key: override value
# Access via symbol or string
puts APP_CONFIG[:key]
puts APP_CONFIG['key']
# Symbolize all keys when using to config other Rails components
ActionMailer::Base.smtp_settings = APP_CONFIG[:mailer][:smtp_settings].symbolize_keys
ActionMailer::Base.default APP_CONFIG[:mailer][:defaults].symbolize_keys
# config/initializers/load_config.rb
config_file = "#{Rails.root}/config/config.yml"
APP_CONFIG = YAML.load_file(config_file)[Rails.env].with_indifferent_access if File.exists?(config_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.