Modeling question

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
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(
area = mainpage.areas.find_by_name(name)%>
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 } %>

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’, …
<%= render :partial => ‘area/area’, …

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 :slight_smile:


page.rhtml :

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

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

On Dec 14, 11:24 am, Gady S. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs