I have some embedded tables that form different sections of a view. I find that I use the same look for certain ones which means I have to duplicate the same exact table for each section that''s similar. Is there a way to do.. hmm.. well.. kind of like what a layout does using @content_for_layout, but for a partial. Does that make any sense whatsoever? :) OK so here''s some pseudocode of maybe a helper or something.. <% view_admin_block "Admin Title" %> This is some content that would go in that block like links to changing usernames, etc. <% end %> What this would do is render a table with all the fancy look-n-feel, borders, all the things that it needs, and it would place "User Administration" in the cell it should go in, and all the content in another one. So something like... <table border="0" cellpadding="0" cellspacing="0"> <tr><td class="admin_title"><%= the_title %></td></tr> <tr><td class="admin_content"><%= @content_for_partial %></td></tr> </table> This is a very simplistic example, but my tables are fairly complex with spacers, different classes, styles, etc. I bring this up because I just noticed that one of my table designs didnt render correctly in IE (big shocker right?). So I have to go through every single partial that uses that same look and fix it to work with IE. -- Posted via http://www.ruby-forum.com/.
The Barge wrote:> I have some embedded tables that form different sections of a view. I > find that I use the same look for certain ones which means I have to > duplicate the same exact table for each section that''s similar. > > Is there a way to do.. hmm.. well.. kind of like what a layout does > using @content_for_layout, but for a partial. Does that make any sense > whatsoever? :) > > OK so here''s some pseudocode of maybe a helper or something.. > > <% view_admin_block "Admin Title" %> > This is some content that would go in that block like links to > changing usernames, etc. > <% end %> > > What this would do is render a table with all the fancy look-n-feel, > borders, all the things that it needs, and it would place "User > Administration" in the cell it should go in, and all the content in > another one. So something like... > > <table border="0" cellpadding="0" cellspacing="0"> > <tr><td class="admin_title"><%= the_title %></td></tr> > <tr><td class="admin_content"><%= @content_for_partial %></td></tr> > </table> > > This is a very simplistic example, but my tables are fairly complex with > spacers, different classes, styles, etc. > > I bring this up because I just noticed that one of my table designs > didnt render correctly in IE (big shocker right?). So I have to go > through every single partial that uses that same look and fix it to work > with IE.You can send variables to a partial, which can then become the content. render :partial => ''table'', :locals => {:the_title => @title, :content => @my_content} and then <table border="0" cellpadding="0" cellspacing="0"> <tr><td class="admin_title"><%= the_title %></td></tr> <tr><td class="admin_content"><%= content %></td></tr> </table> Jeff -- Posted via http://www.ruby-forum.com/.
Jeff Coleman wrote:> You can send variables to a partial, which can then become the content. > > render :partial => ''table'', :locals => {:the_title => @title, :content > => @my_content} > > and then > > <table border="0" cellpadding="0" cellspacing="0"> > <tr><td class="admin_title"><%= the_title %></td></tr> > <tr><td class="admin_content"><%= content %></td></tr> > </table>Yeah, but the content could be a lot of RHTML code depending on how much is displayed in the table block. I''ll check into this more though. It at least gets me heading in the right direction. -- Posted via http://www.ruby-forum.com/.
The Barge wrote:> Jeff Coleman wrote: >> You can send variables to a partial, which can then become the content. >> >> render :partial => ''table'', :locals => {:the_title => @title, :content >> => @my_content} >> >> and then >> >> <table border="0" cellpadding="0" cellspacing="0"> >> <tr><td class="admin_title"><%= the_title %></td></tr> >> <tr><td class="admin_content"><%= content %></td></tr> >> </table> > > Yeah, but the content could be a lot of RHTML code depending on how much > is displayed in the table block. I''ll check into this more though. It > at least gets me heading in the right direction.You can call a partial from within a partial. Why not do that? Jeff -- Posted via http://www.ruby-forum.com/.
Jeff Coleman wrote:> The Barge wrote: >> Jeff Coleman wrote: >>> You can send variables to a partial, which can then become the content. >>> >>> render :partial => ''table'', :locals => {:the_title => @title, :content >>> => @my_content} >>> >>> and then >>> >>> <table border="0" cellpadding="0" cellspacing="0"> >>> <tr><td class="admin_title"><%= the_title %></td></tr> >>> <tr><td class="admin_content"><%= content %></td></tr> >>> </table> >> >> Yeah, but the content could be a lot of RHTML code depending on how much >> is displayed in the table block. I''ll check into this more though. It >> at least gets me heading in the right direction. > > You can call a partial from within a partial. Why not do that?Not sure how this would help me? OK from the main view, lets say "users.rhtml" I render a partial called "admin_accounts". Then, what would it do? Would it render another more generalized partial that represents the look-n-feel (i.e. the table above)? Wouldn''t I need at least two partials for that? One representing the top-half (before <%= content %>) and a second for the bottom half so I could surround the "content" by the rest of the document? <%= render_partial "admin_accounts1" %> Here is the content that goes in this place <%= render_partial "admin_accounts2" %> I''ve been staring at this too long I think :) The solution is probably staring me right in the face. -- Posted via http://www.ruby-forum.com/.
The Barge wrote:> Jeff Coleman wrote: >> The Barge wrote: >>> Jeff Coleman wrote: >>>> You can send variables to a partial, which can then become the content. >>>> >>>> render :partial => ''table'', :locals => {:the_title => @title, :content >>>> => @my_content} >>>> >>>> and then >>>> >>>> <table border="0" cellpadding="0" cellspacing="0"> >>>> <tr><td class="admin_title"><%= the_title %></td></tr> >>>> <tr><td class="admin_content"><%= content %></td></tr> >>>> </table> >>> >>> Yeah, but the content could be a lot of RHTML code depending on how much >>> is displayed in the table block. I''ll check into this more though. It >>> at least gets me heading in the right direction. >> >> You can call a partial from within a partial. Why not do that? > > Not sure how this would help me? OK from the main view, lets say > "users.rhtml" I render a partial called "admin_accounts". Then, what > would it do? Would it render another more generalized partial that > represents the look-n-feel (i.e. the table above)? Wouldn''t I need at > least two partials for that? One representing the top-half (before <%= > content %>) and a second for the bottom half so I could surround the > "content" by the rest of the document? > > <%= render_partial "admin_accounts1" %> > Here is the content that goes in this place > <%= render_partial "admin_accounts2" %> > > I''ve been staring at this too long I think :) The solution is probably > staring me right in the face.There may be a better way to do it, but you could pass the name of the partial to be rendered as a local variable to your "template" partial. render :partial => ''table'', :locals => {:content_for_partial => ''admin_accounts''} _table.rhtml: <table border="0" cellpadding="0" cellspacing="0"> <tr><td class="admin_title"><%= the_title %></td></tr> <tr><td class="admin_content"><%= render :partial => content_for_partial %></td></tr> </table> Again, there may be a better way, but this is at least one option available. Jeff Coleman -- Posted via http://www.ruby-forum.com/.
Jeff Coleman wrote:> render :partial => ''table'', :locals => {:content_for_partial => > ''admin_accounts''} > > _table.rhtml: > > <table border="0" cellpadding="0" cellspacing="0"> > <tr><td class="admin_title"><%= the_title %></td></tr> > <tr><td class="admin_content"><%= render :partial => content_for_partial > %></td></tr> > </table>Copied-and-pasted my own code without changing it completely. You''d want to either send "the_title" as a local variable to the "table" partial, or set @the_title in your controller and use that instead. Jeff Coleman -- Posted via http://www.ruby-forum.com/.
Jeff Coleman wrote:> There may be a better way to do it, but you could pass the name of the > partial to be rendered as a local variable to your "template" partial. > > render :partial => ''table'', :locals => {:content_for_partial => > ''admin_accounts''} > > _table.rhtml: > > <table border="0" cellpadding="0" cellspacing="0"> > <tr><td class="admin_title"><%= the_title %></td></tr> > <tr><td class="admin_content"><%= render :partial => content_for_partial > %></td></tr> > </table> > > Again, there may be a better way, but this is at least one option > available.Sorry for the late reply, but this is working PERFECTLY. I knew there had to be a way to do this so I could encapsulate different parts of the page so everything wasn''t crammed into one big RHTML file. Thanks! -- Posted via http://www.ruby-forum.com/.
The Barge wrote:> Jeff Coleman wrote: >> There may be a better way to do it, but you could pass the name of the >> partial to be rendered as a local variable to your "template" partial. >> >> render :partial => ''table'', :locals => {:content_for_partial => >> ''admin_accounts''} >> >> _table.rhtml: >> >> <table border="0" cellpadding="0" cellspacing="0"> >> <tr><td class="admin_title"><%= the_title %></td></tr> >> <tr><td class="admin_content"><%= render :partial => content_for_partial >> %></td></tr> >> </table> >> >> Again, there may be a better way, but this is at least one option >> available. > > Sorry for the late reply, but this is working PERFECTLY. I knew there > had to be a way to do this so I could encapsulate different parts of the > page so everything wasn''t crammed into one big RHTML file. > > Thanks!Glad it worked out for you! Jeff Coleman -- Posted via http://www.ruby-forum.com/.