How To: Change the redirect path after destroying a session i.e. signing out

afeld edited this page Dec 21, 2012 · 6 revisions
Clone this wiki locally

In your application controller file app/controllers/application_controller.rb include the following private method (below private):

class ApplicationController < ActionController::Base
  private

  # Overwriting the sign_out redirect path method
  def after_sign_out_path_for(resource_or_scope)
    root_path
  end
end

The return value of this method is the redirect url after sign-out, so you should swap root_path to set where devise redirects the users after signing out. The method is overloading the one contained in lib/devise/controllers/helpers.rb within the gem.

You should also override method Devise::Controllers::Helpers#stored_location_for in your application controller, to return nil. This applies to after_sign_in_path_for also. YMMV.