Skip to content

Instantly share code, notes, and snippets.

@eriksk
Created July 6, 2012 09:19
Show Gist options
  • Save eriksk/3059162 to your computer and use it in GitHub Desktop.
Save eriksk/3059162 to your computer and use it in GitHub Desktop.
Config files with YAML in rails.
# config file whatever.yml
development:
my_var: hello
test:
my_var: hello
production:
my_var: hello
# end of config file
# whatever.rb, put this in the initializers folder
# we add the Rails.env to load the config for this environment!
WHATEVER = YAML.load_file("#{Rails.root}/config/whatever.yml")[Rails.env]
# end of whatever.rb
# And then use it wherever you want in your rails app
puts WHATEVER['my_var']
# super easy!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment