# Abstract rails models

**URL:** <https://www.ruby-forum.com/t/abstract-rails-models/181530>\
**Category:** Rails\
**Created:** [January 13, 2010, 10:33am UTC](https://www.ruby-forum.com/t/abstract-rails-models/181530 "2010-01-13T10:33:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecccb3/32.png) [@fredd](https://www.ruby-forum.com/u/fredd)\
**Post date:** [January 13, 2010, 10:33am UTC](https://www.ruby-forum.com/t/abstract-rails-models/181530/1 "2010-01-13T10:33:21Z")

</div>

Hi, I need some advises on rails best practices when it comes to  
abstract/concrete models/classes in Rails. This is what I want to  
accomplish: A abstract type of page that holds base functionality like  
name, memberships, templates and other possible generic stuff. Then I  
want to have subclasses like ProjektPage or CoursePage and these  
classes should of course have it’s own implementations and attributes.  
The only rails way I found on how to do this is with STI, however that  
is not a solution here because the subclasses of page will likely be  
very widespread.

So what are the best technique for handling this problem? I tried  
polymorphic association on the page class and then used a  
has\_one :page on each subclass of page. However this is very hard to  
maintain and hard in new/edit forms. I am desperate for an answer!🙂

Cheers  
Fredrik Martenson

---

<div class="post-metadata">

**Author:** ![fredd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecccb3/32.png) [@fredd](https://www.ruby-forum.com/u/fredd)\
**Post date:** [January 13, 2010, 12:34pm UTC](https://www.ruby-forum.com/t/abstract-rails-models/181530/2 "2010-01-13T12:34:31Z")

</div>

2010/1/13 fredd [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi, I need some advises on rails best practices when it comes to  
> abstract/concrete models/classes in Rails. This is what I want to  
> accomplish: A abstract type of page that holds base functionality like  
> name, memberships, templates and other possible generic stuff. Then I  
> want to have subclasses like ProjektPage or CoursePage and these  
> classes should of course have it’s own implementations and attributes.  
> The only rails way I found on how to do this is with STI, however that  
> is not a solution here because the subclasses of page will likely be  
> very widespread.

It seems possible to me that you are going the wrong way about this.  
Are you wanting classes for the different view pages onto the  
underlying data? It would be more usual to have basic models such as  
User, Project, Course and so on then design the views to combine the  
data from the underlying models as you desire.

Colin

---

<div class="post-metadata">

**Author:** ![fredd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecccb3/32.png) [@fredd](https://www.ruby-forum.com/u/fredd)\
**Post date:** [January 13, 2010, 12:59pm UTC](https://www.ruby-forum.com/t/abstract-rails-models/181530/3 "2010-01-13T12:59:07Z")

</div>

Yes, perhaps I do! I found this blog post about some techniques do add  
behavior to sub classes,  
[a compromise](http://robots.thoughtbot.com/post/159808315/a-compromise).  
I am going to try this right away, thanks for your answer!
