# Question about inherit models and view

**URL:** <https://www.ruby-forum.com/t/question-about-inherit-models-and-view/105203>\
**Category:** Rails\
**Created:** [May 27, 2007, 4:31am UTC](https://www.ruby-forum.com/t/question-about-inherit-models-and-view/105203 "2007-05-27T04:31:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Magicloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Magicloud](https://www.ruby-forum.com/u/Magicloud)\
**Post date:** [May 27, 2007, 4:31am UTC](https://www.ruby-forum.com/t/question-about-inherit-models-and-view/105203/1 "2007-05-27T04:31:17Z")

</div>

## I have some models like this:

## class A \< ActiveRecord; end class B \< A; end

## Now I want to use an action ‘list’ to list out both As and Bs, and I hope every item shows depending on it model. Like this:

## A1: name=xx, age=yy B1: name=mm, age=uu, sex=male A2: name=aa, age=bb

I think this is just a question on polymorphism, right?  
Thanks.

---

<div class="post-metadata">

**Author:** ![Magicloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Magicloud](https://www.ruby-forum.com/u/Magicloud)\
**Post date:** [May 27, 2007, 9:27am UTC](https://www.ruby-forum.com/t/question-about-inherit-models-and-view/105203/2 "2007-05-27T09:27:33Z")

</div>

If you modeled the database as single table inheritance (STI) then  
this is not that hard. You do A.find(:all) to get the objects and  
some will be Bs rather than As.

In your view you can test for whether they are A or B to present the  
right information. Alternatively you can ask them for some piece of  
information that you use to form the name of a partial that will be  
specific to that type such as \_A\_row and \_B\_row with render :partial  
=\> “#{obj.class.name}\_row” or something like that.

Michael
