Forum: Ruby on Rails Subclassing Models

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Meech (Guest)
on 2007-02-04 19:35
(Received via mailing list)
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?
unknown (Guest)
on 2007-02-04 20:05
(Received via mailing list)
Use a mixin.
Alan F. (Guest)
on 2007-02-05 13:08
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

The user stuff you'll need to do yourself.

This topic is locked and can not be replied to.