Assuming we have two different layout files:
application.html.erb– for logged in users
guest.html.erb– for guest users
We can add the following bit of code in our base
class ApplicationController < ActionController::Base layout :layout private def layout user_signed_in? ? 'application' : 'guest' end end
Assuming all our controllers extend
ApplicationController as is the default convention, then our views will use the
application layout when the user is signed in and the
guest layout when they aren’t signed in.
Here, we’re rendering different layouts based on the user’s authentication status but you could use any conditional logic that meets your needs.