I'm just starting out with Rails, and making some ridiculous mistakes along the way.

One of my mistakes was to basically copy the same layout for each controller, not realising that there's such a thing as application.rhtml.

Application.rhtml allows you to create a global template for the whole site. The problem comes when you want to include controller specific bits on the page (like a side bar).

A trick I used (and I'm sure there's probably a million better ways of doing this) is to put a partial in the application.rhtml that you know will be used in the controllers.

For example:

  
application.rhtml

  
  
  
  Your application
  
  
    
<%= render :partial => 'sidebar' %>
<%= yield :layout %>



Then in your controller view folders, include a _sidebar.rhtml partial like this:

  
_sidebar.rhtml in views/user  
This is the User Controller Sidebar  
<%= link_to "logout" %>  


  
_sidebar.rhtml in views/admin  
This is the Admin Controller Sidebar  
<%= link_to "Add User" %>  
<%= link_to "Remove User" %>  

This way you can have a global layout, but also unique side bar details.

Need to find a lawyer for your business? Get in touch with my company Lexoo and we'll find you a great one for free.