Implementing a model with logging?

Hi,

I’ve been trying to work out a model (let’s say a StudentRecord) which
has a number of attributes, and the key thing I’m trying to do here is
to implement it such that you can actually view modifications made over
time by various users (think of it as a wikipedia style of logging).

Is there some provision in rails that’d provide this functionality for
free? Not that I expect something as complicated as this built in but it
is good to know just so I don’t have to reinvent the wheel :slight_smile:

What I was thinking originally is to have a 2nd database table that’d
mirror the attributes owned by the original model to be logged, and each
time an edit takes place I’d just copy the existing values over to the
2nd table before clobbering it with the new values, but such an
implementation can actually get quite unwieldy when I want to have many
of such models.

Another alternative I thought of is to have one special table with
attributes like “type”, “attribute_name” and “value”, where “type” would
designate the original type of the model (ie: StudentRecord),
“attribute_name” would be the name of the changed attribute, and “value”
would be the original value. However such a model does not truly reflect
the real world scenario where multiple attributes can be altered in 1
operation (in this model only 1 attribute can be changed in 1 edit
operation).

Does anyone know of a design pattern or something, such that I can
extend that one original class and get such functionality seamlessly
included in?

I’m all ears :slight_smile:

On 3/22/06, Woei S. [email protected] wrote:

Hi,

I’ve been trying to work out a model (let’s say a StudentRecord) which
has a number of attributes, and the key thing I’m trying to do here is
to implement it such that you can actually view modifications made over
time by various users (think of it as a wikipedia style of logging).

Is there some provision in rails that’d provide this functionality for
free? Not that I expect something as complicated as this built in but it
is good to know just so I don’t have to reinvent the wheel :slight_smile:

Check out the “acts_as_versioned” plugin. It’s pretty much exactly
what you’re looking for, if I understood you correctly:
http://ar-versioned.rubyforge.org/