Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise: Logout *without* redirecting?

Im trying to logout with devise but without redirecting! So I want to disable the redirect after logout. The reason for this is I want to render a certain template instead. How to logout a user from devise without redirecting them for --> this method only <--? Im already overriding the devise session controller.

My method ( called from before filter in application_controller.rb)

  def check_concurrent_session
    if user_signed_in?
      if current_user && !(session[:token] == current_user.login_token)
        render :template => "users/logout_duplex", :layout => "application", :locals => { sub_layout => "left" }
        # The next line always redirects to signout_path
        # I want to disable the complete redirect so it just logs out and shows the rendered template
        Devise.sign_out_all_scopes ? sign_out : sign_out(@user)
        return
      end
    end
  end
like image 270
Rubytastic Avatar asked Oct 15 '13 15:10

Rubytastic


1 Answers

Inherit sessions controller from devise and have your own implementation of after_sign_out_path_for. That's the method devise uses to redirect after signout.

class SessionsController < Devise::SessionsController

 protected
 def after_sign_out_path_for(resource)
  //your implementation
 end
end

Add this to your config/routes.rb

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

Devise implementation of the method looks like below

def after_sign_out_path_for(resource_or_scope)
 respond_to?(:root_path) ? root_path : "/"
end
like image 147
usha Avatar answered Sep 20 '22 20:09

usha