Hi, I''m a RoR noob so excuse me if this is an obvious question. I''ve looked in all my RoR books (I have 5) and tried to find the answer in the newsgroups but to no avail. I have an application layout which defines the layout of the site which has a left and right column and a content column in the middle (3 col layout). The left/right column contents can change depending on the current action, so for example for my login form I do not want anything displayed in the left but I do for the right. Once logged in I want something in both columns, the content changes as the user navigates the site. My thoughts where to use partials so that the view is responsible for what gets displayed in these columns. I would have something like this in the application layout: <div id="right"> <%= render (:partial => "rightcolumn") %> </div> <!-- right --> I would then define _righcolumn.rhtml for each view. Is this the correct approach, in those cases where I do not display anything in either column would I have to include a blank partial??? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
# in layout file (For ex. application.rhtml) <div id="right"> <%= yield :right %> </div> <div id="left"> <%= yield :left %> </div> # in any view (*.rhtml) that you want to fill the div... <% content_for :right do -%> <!-- your stuff --> <% end -%> <!-- and/or --> <% content_for :left do -%> <!-- your stuff --> <% end -%> HTH - H On 6/11/07, springbok <evt-5KZZ8/93A+Y0n/F98K4Iww@public.gmane.org> wrote:> > Hi, > > I''m a RoR noob so excuse me if this is an obvious question. I''ve > looked in all my RoR books (I have 5) and tried to find the answer in > the newsgroups but to no avail. > > I have an application layout which defines the layout of the site > which has a left and right column and a content column in the middle > (3 col layout). > > The left/right column contents can change depending on the current > action, so for example for my login form I do not want anything > displayed in the left but I do for the right. Once logged in I want > something in both columns, the content changes as the user navigates > the site. > > My thoughts where to use partials so that the view is responsible for > what gets displayed in these columns. I would have something like this > in the application layout: > > <div id="right"> > <%= render (:partial => "rightcolumn") %> > </div> <!-- right --> > > I would then define _righcolumn.rhtml for each view. > > Is this the correct approach, in those cases where I do not display > anything in either column would I have to include a blank partial??? > > Thanks. > > > > >-- Husein Choroomi Yucca Intelligence Development http://www.YuccaHQ.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 -~----------~----~----~----~------~----~------~--~---
That is one approach. The downside is that you must provide the partial for every view. If on the other hand you allow the controller to name the partials you can share partials between views. For example: <div id="right> <%= render :partial => @right_partial %> </div> Then the controller can do things like: @right_partial = "shared/shared_view1" Which references view shared_view1 in the shared directory. Michael On Jun 11, 1:17 am, springbok <e...-5KZZ8/93A+Y0n/F98K4Iww@public.gmane.org> wrote:> Hi, > > I''m a RoR noob so excuse me if this is an obvious question. I''ve > looked in all my RoR books (I have 5) and tried to find the answer in > the newsgroups but to no avail. > > I have an application layout which defines the layout of the site > which has a left and right column and a content column in the middle > (3 col layout). > > The left/right column contents can change depending on the current > action, so for example for my login form I do not want anything > displayed in the left but I do for the right. Once logged in I want > something in both columns, the content changes as the user navigates > the site. > > My thoughts where to use partials so that the view is responsible for > what gets displayed in these columns. I would have something like this > in the application layout: > > <div id="right"> > <%= render (:partial => "rightcolumn") %> > </div> <!-- right --> > > I would then define _righcolumn.rhtml for each view. > > Is this the correct approach, in those cases where I do not display > anything in either column would I have to include a blank partial??? > > Thanks.--~--~---------~--~----~------------~-------~--~----~ 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 suspect you may want to use different layouts depending on the circumstance. You may also me interested in the nested layouts plugin(http://agilewebdevelopment.com/plugins/nested_layouts), I''ve found it quite useful for these types of things. good luck! Tim On Jun 11, 1:17 am, springbok <e...-5KZZ8/93A+Y0n/F98K4Iww@public.gmane.org> wrote:> Hi, > > I''m a RoR noob so excuse me if this is an obvious question. I''ve > looked in all my RoR books (I have 5) and tried to find the answer in > the newsgroups but to no avail. > > I have an application layout which defines the layout of the site > which has a left and right column and a content column in the middle > (3 col layout). > > The left/right column contents can change depending on the current > action, so for example for my login form I do not want anything > displayed in the left but I do for the right. Once logged in I want > something in both columns, the content changes as the user navigates > the site. > > My thoughts where to use partials so that the view is responsible for > what gets displayed in these columns. I would have something like this > in the application layout: > > <div id="right"> > <%= render (:partial => "rightcolumn") %> > </div> <!-- right --> > > I would then define _righcolumn.rhtml for each view. > > Is this the correct approach, in those cases where I do not display > anything in either column would I have to include a blank partial??? > > Thanks.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks everyone for your suggestions, I''ve taken Michael''s approach as I think it will best suit my needs. An added bonus is that I will be able to share partials in those cases where the same content is displayed in the left/right columns. --~--~---------~--~----~------------~-------~--~----~ 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 also use conditions in my layout for this kinda stuff a bit, stuff like <% unless @user.logged_in==true %> ... do some stuff <% else %> ... do some other stuff <% end %> Doesn''t feel as "Railsy" but it''s a darn site easier to read and debug. Cam On Jun 12, 12:56 pm, springbok <e...-5KZZ8/93A+Y0n/F98K4Iww@public.gmane.org> wrote:> Thanks everyone for your suggestions, I''ve taken Michael''s approach as > I think it will best suit my needs. An added bonus is that I will be > able to share partials in those cases where the same content is > displayed in the left/right columns.--~--~---------~--~----~------------~-------~--~----~ 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''m sure this is known, but just to take Michael''s example one simple step further you could add an if statement to only render if the @right_partial varible has been set. <div id="right> <% if @right_partial %> <%= render :partial => @right_partial %> <% else %> <!-- do other stuff --> <% end %> </div> On Jun 11, 11:22 am, MichaelLatta <lat...-ee4meeAH724@public.gmane.org> wrote:> That is one approach. The downside is that you must provide the > partial for every view. > > If on the other hand you allow the controller to name the partials you > can share partials between views. For example: > > <div id="right> > <%= render :partial => @right_partial %> > </div> > > Then the controller can do things like: > > @right_partial = "shared/shared_view1" > > Which references view shared_view1 in the shared directory. > > Michael > > On Jun 11, 1:17 am, springbok <e...-5KZZ8/93A+Y0n/F98K4Iww@public.gmane.org> wrote: > > > Hi, > > > I''m a RoR noob so excuse me if this is an obvious question. I''ve > > looked in all my RoR books (I have 5) and tried to find the answer in > > the newsgroups but to no avail. > > > I have an application layout which defines the layout of the site > > which has a left and right column and a content column in the middle > > (3 col layout). > > > The left/right column contents can change depending on the current > > action, so for example for my login form I do not want anything > > displayed in the left but I do for the right. Once logged in I want > > something in both columns, the content changes as the user navigates > > the site. > > > My thoughts where to use partials so that the view is responsible for > > what gets displayed in these columns. I would have something like this > > in the application layout: > > > <div id="right"> > > <%= render (:partial => "rightcolumn") %> > > </div> <!-- right --> > > > I would then define _righcolumn.rhtml for each view. > > > Is this the correct approach, in those cases where I do not display > > anything in either column would I have to include a blank partial??? > > > Thanks.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---