Rails & Devise: How to render login page without a layout?

neezer picture neezer · Dec 10, 2010 · Viewed 25k times · Source

I know this is probably a simple question, but I'm still trying to figure Devise out...

I want to render :layout => false on my login page; how can I do this with Devise?

Answer

iain picture iain · Dec 10, 2010

You can subclass the controller and configure the router to use that:

class SessionsController < Devise::SessionsController
  layout false
end

And in config/routes.rb:

devise_for :users, :controllers => { :sessions => "sessions" }

You need to move the session views to this controller too.

OR make a method in app/controllers/application_controller.rb:

class ApplicationController < ActionController::Base

  layout :layout

  private

  def layout
    # only turn it off for login pages:
    is_a?(Devise::SessionsController) ? false : "application"
    # or turn layout off for every devise controller:
    devise_controller? && "application"
  end

end