On Personal Configurations
January 3, 2012 § Leave a comment
In a lot of the Rails projects I work on we use yaml files to set up configuration variables, things like domain urls, facebook and paypal keys, smtp configurations and many more. A lot of these can be different across different environments. The domain we use in our development environment might look like 127.0.0.1:3000
where in production it would look like awesome.com
. We use Rails’s database.yml as a template for the rest of our configuration files, so an example of our config/config.yml
might look like this:
test: name: AppName host: 127.0.0.1:3000 push_endpoint: http://lvho.st:8080/app/cometd development: name: AppName host: lvho.st:3000 push_endpoint: http://lvho.st:8080/app/cometd user_dev_tweaks: false production: name: AppName host: sweetdomain.com push_endpoint: http://sweetdomain.com:8080/app/cometd
We then slurp the current environment’s settings into a global constant in config/application.rb
with the following:
CONFIG = YAML.load_file("#{::Rails.root.to_s}/config/config.yml")[::Rails.env].symbolize_keys
See all of the code in the gist for easier reading.
Leave a Reply