Forum: Ruby on Rails Subclassing Models

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.
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
DATETIME field.

The user stuff you'll need to do yourself.

A.
This topic is locked and can not be replied to.