# Implementing a model with logging?

**URL:** <https://www.ruby-forum.com/t/implementing-a-model-with-logging/55705>\
**Category:** Rails\
**Created:** [March 23, 2006, 3:48am UTC](https://www.ruby-forum.com/t/implementing-a-model-with-logging/55705 "2006-03-23T03:48:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![generik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4da419/32.png) [@generik](https://www.ruby-forum.com/u/generik)\
**Post date:** [March 23, 2006, 3:48am UTC](https://www.ruby-forum.com/t/implementing-a-model-with-logging/55705/1 "2006-03-23T03:48:47Z")

</div>

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 🙂

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 🙂

---

<div class="post-metadata">

**Author:** ![generik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4da419/32.png) [@generik](https://www.ruby-forum.com/u/generik)\
**Post date:** [March 23, 2006, 3:54am UTC](https://www.ruby-forum.com/t/implementing-a-model-with-logging/55705/2 "2006-03-23T03:54:36Z")

</div>

On 3/22/06, Woei S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 🙂

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/](http://ar-versioned.rubyforge.org/)
