[Rails] Creating a model that acts as a settings manager

Iván Vega Rivera ivanvega at gmail.com
Wed Jan 4 23:44:26 GMT 2006


Hi,

I was wondering how could you create a model that is tied to all the 
records in one table, and retrieves the values of all records on first 
load, and also handles the updating of its values.

For example, suppose I have this table:

id INT(11) PK
group CHAR(40)
name CHAR(40)
value CHAR(128)
updated_at DATETIME

Sample rows:
group   name   value
---------------------------
main   something   123
users   expire   45

Then, I'd like very much to do something like this in Rails:

Settings.main.something = 34
a = Settings.users.expire

And also being able to override default behaviors, because maybe I'd 
want to do something special each time a specific setting is changed.

Currently, I'm just defining a method for each setting, but I keep 
thinking there must be a better way.

Thanks in advance!

- Ivan V.



More information about the Rails mailing list