Wow.. everyday.. Ruby on Rails seems to amuse me.. I just figured how to seperate layouts just by having different files in the layouts/ which corresponds to a controller. If a layout file “home (home.html.erb)” exists and there is home_controller, then the home_controller would use that layout instead of application.html.erb.

Now.. I haven’t validated this concept by book and would do so soon..

Picture 1.png
Fig 1

Another way is specifying a filter…

  1. In application.rb, specify a method that displays the ‘admin’ layout if the user is admin.
    def load_layout
      if admin?
        self.class.layout('admin')
      end
    end
  1. home_controller
class HomeController < ApplicationController
  before_filter :load_layout
end

Picture 2.png
Fig 2. admin.html.erb now exists in layouts/

Reference:
http://railscasts.com/episodes/125-dynamic-layouts