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
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%>

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’, …

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:

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. [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