Over a million developers have joined DZone.

App Level Configuration For Your Rails Apps

·
Hard coding stuff into your view templates isn't a great idea, and sometimes you want it out of your layouts too. If you have variables your app requires, but which may change between deployments, put them in /config/appconfig.yml in YAML format, then put this at the top of your /config/environment.rb:

require 'yaml'

And at the bottom of your /config/environment.rb:

APP_CONFIG = YAML::load(File.open("#{RAILS_ROOT}/config/appconfig.yml"))

Now your YAML variables are accessible anywhere from your controllers or views like so:

APP_CONFIG["variable"]

Easy peasy.
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}