Aaron Dufall
Aaron Dufall

Reputation: 1177

Rails: Multiple layouts with Devise

How can I have a completely different layout depending on wether a user is logged in or not?

Upvotes: 0

Views: 640

Answers (1)

Michael Durrant
Michael Durrant

Reputation: 96484

Follow the instructions at
https://github.com/plataformatec/devise/wiki/How-To%3a-Create-custom-layouts
and make the check be if the user is logged in, which for devise means checking
user_signed_in?, which is a devise helper.

Specifically:

class ApplicationController < ActionController::Base
  layout :layout_by_resource

  protected

  def layout_by_resource
    if user_signed_in?
      "special_layout_name_for_logged_in"
    else
      "application"
    end
  end
end

and put the special_layout_for_logged_in.html.erb view file in the layouts directory.

Upvotes: 1

Related Questions