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 :
<div id="extras">
<%= render :partial => ''area'', :locals => { :name
=> ''right'' } %>
</div>
<div id="content">
<%= render :partial => ''area'', :locals => {
:name => ''main'' } %>
</div>
_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%>
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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'', ... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 : <div id="extras"> <%= render :partial =>''area'', :collection => @page.areas %> </div> _area.rhtml <%=render :partial =>''somelementcode'', :collection => area.elements %> On Dec 14, 11:24 am, Gady Sujo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 : > <div id="extras"> > <%= render :partial => ''area'', :locals => { :name => ''right'' } %> > </div> > <div id="content"> > <%= render :partial => ''area'', :locals => { :name => ''main'' } %> > </div> > > _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%> > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---