Forum: Ruby on Rails rendering subtemplates

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
365c8238c216cfb90572ef1086c0cb0e?d=identicon&s=25 lester bangs (Guest)
on 2006-02-04 21:14
(Received via mailing list)
hi,

i've got main site navigation in the application.rhtml file.
the links in this template correspond to the 'index'
page of various controllers.  The controllers themselves
each have navigation of their own, which i would like to
appear in every view for a particular controller in *addition*
to the main site navigation.

The problem I am encountering is that when the app runs,
the individual controller layouts take precedence over
the layouts in application.rhtml which effectively
removes the site navigation.

what is the preferred rails way of allowing both a
site-wide layout regardless of controller simultaneously
with a per-controller layout?

thanks!
00b25ade726ce4fb538d3d8cf47a750b?d=identicon&s=25 Harvey Bernstein (Guest)
on 2006-02-04 21:35
Please bear in mind that I am a newbie and this may not be the preferred
way to do this:-

In the main application_helper I have this method:-

 # Returns the name of the partial used for the application menu
  def application_menu
    @application_menu || 'shared/application_menu'
  end

If I want to override this for individual controllers, all I need to do
is create the appropriate method in the correct helper, like so:-


  def application_menu
    @application_menu || 'shared/agecare_menu'
  end


Now in my layout which is the main application.rhmtl  I have

<%= render :partial =>"shared/html_head" %>
<body class= "<%= @controller.controller_name %>" >
      <div id="wrapper">
        <%= render :partial => application_menu %>
              <div id="content">
                <div id="content2">
                    <%= show_flash_messages :textilize => true %>
                    <%= @content_for_layout %>
                      <div id="clear">&nbsp;
                    </div>
                </div>
            </div>
        <%= render :partial =>"shared/footer" %>
    </div>
</body>
</html>


Here is example code for one of my partial menus, in this case
shared/agecare_menu:-

<div id="extranet_menu">
    <%= render :partial => 'shared/top_menu' %>
    <h1><a href="/innovate">iNNOVATE</a></h1>
     <ul id="main_menu">
          <li class="first" id="home"><%= link_to "Nursing and
Residential Homes", :controller =>
        'home', :action => "index" %></li>
        <li id="home_support"><%= link_to "Home Support Agencies",
:controller =>
        'home_support', :action => "index" %></li>
        <li id="sheltered_development"><%= link_to "Sheltered
Developments",
        :controller => 'sheltered_development', :action => "index"
%></li>
      </ul>
</div>

The _top_menu partial is shared between the whole application.  Hope
this helps
Regards
Harvey


On 4/2/06 20:07, "lester bangs" <dumpingrounds@gmail.com> wrote:

> hi,
>
> i've got main site navigation in the application.rhtml file.
> the links in this template correspond to the 'index'
> page of various controllers.  The controllers themselves
> each have navigation of their own, which i would like to
> appear in every view for a particular controller in *addition*
> to the main site navigation.
>
> The problem I am encountering is that when the app runs,
> the individual controller layouts take precedence over
> the layouts in application.rhtml which effectively
> removes the site navigation.
>
> what is the preferred rails way of allowing both a
> site-wide layout regardless of controller simultaneously
> with a per-controller layout?
>
> thanks!
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
> This e-mail has been scanned for all viruses by MessageLabs.


lester bangs wrote:
> hi,
>
> i've got main site navigation in the application.rhtml file.
> the links in this template correspond to the 'index'
> page of various controllers.  The controllers themselves
> each have navigation of their own, which i would like to
> appear in every view for a particular controller in *addition*
> to the main site navigation.
>
> The problem I am encountering is that when the app runs,
> the individual controller layouts take precedence over
> the layouts in application.rhtml which effectively
> removes the site navigation.
>
> what is the preferred rails way of allowing both a
> site-wide layout regardless of controller simultaneously
> with a per-controller layout?
>
> thanks!
00b25ade726ce4fb538d3d8cf47a750b?d=identicon&s=25 Harvey Bernstein (Guest)
on 2006-02-04 21:36
(Received via mailing list)
Please bear in mind that I am a newbie and this may not be the preferred
way
to do this:-

In the main application_helper I have this method:-

 # Returns the name of the partial used for the application menu
  def application_menu
    @application_menu || 'shared/application_menu'
  end

If I want to override this for individual controllers, all I need to do
is
create the appropriate method in the correct helper, like so:-


  def application_menu
    @application_menu || 'shared/agecare_menu'
  end


Now in my layout which is the main application.rhmtl  I have

<%= render :partial =>"shared/html_head" %>
<body class= "<%= @controller.controller_name %>" >
      <div id="wrapper">
        <%= render :partial => application_menu %>
              <div id="content">
                <div id="content2">
                    <%= show_flash_messages :textilize => true %>
                    <%= @content_for_layout %>
                      <div id="clear">&nbsp;
                    </div>
                </div>
            </div>
        <%= render :partial =>"shared/footer" %>
    </div>
</body>
</html>


Here is example code for one of my partial menus, in this case
shared/agecare_menu:-

<div id="extranet_menu">
    <%= render :partial => 'shared/top_menu' %>
    <h1><a href="/innovate">iNNOVATE</a></h1>
     <ul id="main_menu">
          <li class="first" id="home"><%= link_to "Nursing and
Residential
Homes", :controller =>
        'home', :action => "index" %></li>
        <li id="home_support"><%= link_to "Home Support Agencies",
:controller =>
        'home_support', :action => "index" %></li>
        <li id="sheltered_development"><%= link_to "Sheltered
Developments",
        :controller => 'sheltered_development', :action => "index"
%></li>
      </ul>
</div>

The _top_menu partial is shared between the whole application.  Hope
this
helps
Regards
Harvey


On 4/2/06 20:07, "lester bangs" <dumpingrounds@gmail.com> wrote:

> the individual controller layouts take precedence over
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
> This e-mail has been scanned for all viruses by MessageLabs.


This e-mail has been scanned for all viruses by MessageLabs.
This topic is locked and can not be replied to.