# Object Oriented Partials

**URL:** <https://www.ruby-forum.com/t/object-oriented-partials/118760>\
**Category:** Rails\
**Created:** [October 30, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/object-oriented-partials/118760 "2007-10-30T18:19:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve13o](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@steve13o](https://www.ruby-forum.com/u/steve13o)\
**Post date:** [October 30, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/object-oriented-partials/118760/1 "2007-10-30T18:19:33Z")

</div>

Are there any plugins/mixins that provide an OO partial view  
framework?  
e.g  
If A \< B (subclass) and A \< C,  
As I’m rendering a list of A’s, depending on the type of A, attempts  
to render \_B\_as\_listitem or \_C\_as\_listitem first, otherwise render’s  
\_A\_as\_listitem (super), each partial would take the an object of type  
A as a param.

This would be a bad implementation of the idea:

models

class A \< ActiveRecord::Base  
class B \< A  
class C \< A

AController  
def list  
@list\_of\_a = A.find(:all)  
end

list.html.erb

\<% for a in @list\_of\_a %\>  
\<% render :partial =\> ‘A\_as\_list\_item’, :locals =\> {:object =\> a} %\>  
\<%end%\>

\_A\_as\_list\_item

case a[:type]  
when ‘B’  
\<% render :partial =\> ‘B\_as\_list\_item’, :locals =\> {:object =\> a}  
%\>  
when ‘C’  
\<% render :partial =\> ‘C\_as\_list\_item’, :locals =\> {:object =\> a}  
%\>  
end

---

<div class="post-metadata">

**Author:** ![steve13o](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@steve13o](https://www.ruby-forum.com/u/steve13o)\
**Post date:** [October 30, 2007, 6:48pm UTC](https://www.ruby-forum.com/t/object-oriented-partials/118760/2 "2007-10-30T18:48:50Z")

</div>

On Tue, Oct 30, 2007 at 05:18:29PM -0000, steve13o wrote:

> list.html.erb
> 
> \<% for a in @list\_of\_a %\>  
> \<% render :partial =\> ‘A\_as\_list\_item’, :locals =\> {:object =\> a} %\>  
> \<%end%\>  
> […]

\<% @list\_of\_a do |a| -%\>  
\<%= render :partial =\> “#{a.class}\_as\_list\_item”, :object =\> a %\>  
\<% end -%\>

–Greg
