Every rails app I’ve ever built needs some sort of configuration, and I seem to be solving this problem a different way every time, which really bothers me. Today I learned about a new class called OpenStruct. Here’s how you could use it.
# in app_root/config/initializers/app_config.rb
require 'ostruct'
AppConfig = OpenStruct.new
AppConfig.default_email = "no-reply@example.com"
AppConfig.api_url = "staging.someapi.com"
Now you have a neat way of defining global configuration variables without using constants or defining custom classes.
This tip was submitted by Jon Druse.
You can use HTML tags for formatting. Wrap code in <code> tags and multiple lines of code in <pre><code> tags.