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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading On Personal Configurations at The On Blog.

meta

%d bloggers like this: