Forum: Ruby on Rails Implementing a model with logging?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fcdafe495dccc04d27f6dbbcdf54aecc?d=identicon&s=25 Woei Shyang (generik)
on 2006-03-23 03:48
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 :)
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-03-23 03:54
(Received via mailing list)
On 3/22/06, Woei Shyang <woeishyang@gmail.com> 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/
This topic is locked and can not be replied to.