# Subclassing Models

**URL:** <https://www.ruby-forum.com/t/subclassing-models/84442>\
**Category:** Rails\
**Created:** [February 4, 2007, 6:35pm UTC](https://www.ruby-forum.com/t/subclassing-models/84442 "2007-02-04T18:35:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@Meech](https://www.ruby-forum.com/u/Meech)\
**Post date:** [February 4, 2007, 6:35pm UTC](https://www.ruby-forum.com/t/subclassing-models/84442/1 "2007-02-04T18:35:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Meech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@Meech](https://www.ruby-forum.com/u/Meech)\
**Post date:** [February 4, 2007, 7:05pm UTC](https://www.ruby-forum.com/t/subclassing-models/84442/2 "2007-02-04T19:05:02Z")

</div>

Use a mixin.

---

<div class="post-metadata">

**Author:** ![Meech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@Meech](https://www.ruby-forum.com/u/Meech)\
**Post date:** [February 5, 2007, 12:08pm UTC](https://www.ruby-forum.com/t/subclassing-models/84442/3 "2007-02-05T12:08:02Z")

</div>

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.
