elikem
5/30/2015 - 1:20 PM

Loading YAML file with Rails ENV VARS

Loading YAML file with Rails ENV VARS

username: "admin"
password: "secret"
secret_token: "024e1460..."
development:
  host: "localhost:3000"
test:
  host: "test.local"
production:
  host: "blog.example.com"
config = YAML.load(File.read(File.expand_path('../application.yml', __FILE__)))
config.merge! config.fetch(Rails.env, {})
config.each do |key, value|
  ENV[key] = value unless value.kind_of? Hash
end
 
config.action_mailer.default_url_options = { host: ENV[:host] }
# Protects against namespace clashes with the host OS
CONFIG = YAML.load(File.read(File.expand_path('../application.yml', __FILE__)))
CONFIG.merge! CONFIG.fetch(Rails.env, {})
CONFIG.symbolize_keys!

config.action_mailer.default_url_options = { host: CONFIG[:host] }