I have little problems with nested layouts. On my site I need to make one separate part of the site only for administrator.
I have this in my application.html.erb
file:
<body>
<%= render 'layouts/header' %>
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
</div>
</body>
I was wondering how can I now make another template like this to be inserted inside <%= yield %>
because for administrator part I again need fixed parts of the site like header
and footer
in main layout. Instead of header
and footer
I will have two menus. I want <%= yield %>
to be filled with new template which will have menu on top and new <%= yield %>
which will be filled with actions from admin controller. So, menu will always stay on top.
I've made a menu partial views/admins/_menu.html.erb
:
<div>
<div>
<div class="container">
<ul>
<li><%= link_to "Action1", '#' %></li>
<li><%= link_to "Action2", '#' %></li>
<li><%= link_to "Action3", '#' %></li>
</ul>
</div>
</div>
</div>
My new layout is layouts/sublayouts/admin.html.erb
:
<%= render 'admins/menu' %>
<%= yield %>
Currently alternative is to render views/admins/_menu.html.erb
in each view on top but that doesn't look as a good solution to me.
Regular site would have this structure:
Header/Menu
|
Container
|Content
Footer
And admin site would have this structure:
Header/Menu
|
Container
|Content
|Admin Menu
|Admin Content
|
Footer
What would be the best way to accomplish this?