# Modeling question

**URL:** <https://www.ruby-forum.com/t/modeling-question/123174>\
**Category:** Rails\
**Created:** [December 14, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/modeling-question/123174 "2007-12-14T17:24:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gadys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gadys](https://www.ruby-forum.com/u/gadys)\
**Post date:** [December 14, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/modeling-question/123174/1 "2007-12-14T17:24:24Z")

</div>

Hi All,  
I’m have this domain model:  
a page has many areas which has many elements.  
I’m generating a page by generating it’s areas which in turn generate  
the elements.  
the problem is that currently the page show action generates the layout  
and then render the different partials for each area. the area render  
the diffrent elements buy all of the partials are in the view/page  
directory.  
how can i separate the responsibilities between the object so that each  
object will know the render it self ? should i just move the partials to  
another directory and render from there ? how ?

Thank you

here’s my code :  
page.rhtml :

\<%= render :partial =\> 'area', :locals =\> { :name =\> 'right' } %\>

 \<%= render :partial =\> 'area', :locals =\> { :name =\> 'main' } %\>

\_area.rhtml :  
\<%area = @page.areas.find\_by\_name(name)  
if area.overide==true then  
mainpage = Page.find(@page.site.mainid)  
area = mainpage.areas.find\_by\_name(name)%\>  
\<%=“ovvver”%\>  
\<%end  
elements = area.elements.sort{ |x,y| x.position \<=\> y.position }  
elements.each do |element|%\>  
\<% if element.pratialname!="" then %\>  
\<%=render :partial =\> element.pratialname , :locals =\> { :element  
=\> element } %\>  
\<%else%\>  
\<%=element.content%\>  
\<%end%\>  
\<%end%\>

---

<div class="post-metadata">

**Author:** ![gadys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gadys](https://www.ruby-forum.com/u/gadys)\
**Post date:** [December 14, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/modeling-question/123174/2 "2007-12-14T17:35:13Z")

</div>

sorry, i don’t get the details of your problem,  
but why not just use the partials out of the other directory:

\<%= render :partial =\> ‘page/area’, …  
or  
\<%= render :partial =\> ‘area/area’, …

---

<div class="post-metadata">

**Author:** ![gadys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gadys](https://www.ruby-forum.com/u/gadys)\
**Post date:** [December 15, 2007, 3:09am UTC](https://www.ruby-forum.com/t/modeling-question/123174/3 "2007-12-15T03:09:15Z")

</div>

I am finding this a little confusing as well seeing this out of  
context but why not pass in the area objects through the  
render :collection parameter.

if your Area model has\_many :elements, :order =\> :position  
and you pass your collection of elements in the same way everything  
should come down the way you ordered it.

I know I left out a little of your logic, but I don’t understand the  
purpose for it 🙂

so:

page.rhtml :

\<%= render :partial =\>'area', :collection =\> @page.areas %\>

\_area.rhtml  
\<%=render :partial =\>‘somelementcode’, :collection =\> area.elements %\>

On Dec 14, 11:24 am, Gady S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
