Keep CSS layout in layouts not in view pages
When using layouts in Rails, I strongly suggest keeping as much of the container elements in the layout and using content_for to create sections in which content can be placed.
I am working on a site right now that has used the YUI Grids to layout the site (something I highly recommend for anyone designing a site from scratch). Most of the site uses a two column layout. The application.html.erb file looks like this:
<body>
<div id="doc" class="yui-t6">
<div id="hd" role="banner">
<%= render_partial "shared/header" %>
</div>
<div id="bd" role="main">
<%= yield :content %>
</div>
<div id="ft" role="contentinfo">
<%= render_partial "shared/footer" %>
</div>
</div>
</body>
What is missing is the part that divides the page into your content area and your, in this case, right-hand side area. This part was placed in the rest of the view files. Not only does this mean that it is repeated everywhere and a huge pain to change, it also means that it is much harder for coders, who may not know YUI CSS Grids, to properly lay out pages. In the case of the app that I am modifying, it has also meant that parts of the CSS layout are strewn careless between regular pages and partials.
Instead, this is how the layout page should look:
<body>
<div id="doc" class="yui-t6">
<div id="hd" role="banner">
<%= render_partial "shared/header" %>
</div>
<div id="bd" role="main">
<div id="yui-main">
<div class="yui-b">
<div class="yui-g">
<%= yield :content %>
</div>
</div>
</div>
<div class="yui-b">
<%= yield :side_content %>
</div>
</div>
<div id="ft" role="contentinfo">
<%= render_partial "shared/footer" %>
</div>
</div>
</body>
This keeps everything clean and makes for view pages that look like the following.
<% content_for :content do %> put content here <% end %> <% content_for :side_content do %> put side content here <% end %>
I think that makes it much easier to see what is happening within view pages. It also keeps all the layout code in one place.