The dominant convention for storing editable application parameters as a whole seems to be the concept of a keystore supported by either ActiveRecord or other mechanisms. And, as far as I know, there are at least two good strategies for storing the settings of your application depending on your details.
If you need a general approach, but extremely flexible for defining several (non) areas that may be associated with AR models, you are Rails-Settings (or its cached version of Rails-Settings-Cached ). I have not tried using the plugin in Rails 3.1, but it works well on version 3.0. This allows you to have things like:
Settings.main_color = '#3333CC' Settings.logo_file_name = 'images/logo.png' Setting['preferences.color'] = :blue
In case you need a reliable approach using Single-Table-Inheritance and allowing you to perform checks in certain settings, as is the case with actual AR Records, you have this good article written by Jeff Dean that will help you in this process. This way you set the parameters by grouping them into subclasses, and you can have things like:
class ApplicationSettings::PageLayout < ApplicationSetting validates :title, :presence => true ... def title value end def title=(value) self.value = value end
And I assume that with some simple setup, you might even have has_many and belongs_to in some of your settings (for example, a list of phone numbers or emails with a variable size).
Personally, I prefer the latter approach (when settings are a big problem) as it gives you more control over the settings you store and keeps your code clean and dry, which allows you to follow the MVC pattern.
source share