Subclassing Models


#1

Not even sure I have the right terminology here, Ruby/Rails syntax is
a bit of a challenge to get my brain wrapped around.

The majority of my models will have a timestamp/userstamp (updated_on,
updated_by) type thing. I haven’t really settled on an
authentication method yet, but was wondering how I might add this in a
DRY fashion to my models. I looked at the userstamp plugin, but I
don’t want foreign keys, and I want to learn how to roll this myself.

What’s the best ruby-esque way to achieve this?

Would I somehow construct a standard decorator for the model?
Would I subclass a base record somehow, check for the existance of the
fields and stuff them?

I know I could do this on a model by model basis using a before_update
type thing, but how do I DRY it?


#2

Use a mixin.


#3

unknown wrote:

Use a mixin.

Also be aware that Rails gives you created_[at|on] and updated_[at|on]
functionality for free. If those fields exist, rails will fill them in
form you. the _on variety is a DATE filed, the _at variety is a
DATETIME field.

The user stuff you’ll need to do yourself.

A.