An alternative approach that we’ve tried in a couple of our apps is to extend Rails::Configuration to add our own settings. The nice thing about this approach is it lets us easily have different settings for different environments, with defaults and everything, just like the built in rails configuration options, and all checked in to svn. The downside is that we haven’t been able to figure out a way to do it without creating a global reference to the config object, which creates some awkward coupling between the config and whatever uses it, such as model objects. Its pretty easy to do, though.
class MyConfig < Rails::Configuration
#define attributes or whatever
MY_CONFIG = MyConfig.new
Rails::Initializer(:process, MY_CONFIG) do |config|
#all the usual config stuff
config.my_custom_setting = “default value”
Then wherever you need the configuration value, you can check it:
filename = MY_CONFIG.my_custom_setting
We also tried a more dependency injection based approach, where the config object would set values for the classes that needed them. We ran into problems when classes are reloaded in development mode, though - everything would work fine on the first request, but on subsequent requests the class would have been reloaded, losing the values that had been set before, but the environment code does not get re-run so we would end up not having the values set at all.
Just an idea, and Ezra’s approach will certainly work great for storing the values in the database.