Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 reset session using devise

I am developing a Rails3 application using Devise for authentication. In the course of the workflow, data like patient_id is stored in the session. However, when the user log's out, the session needs to be cleared. I am unable to figure out how to reset session data since Devise handles users login / logout and I not having control over it.

How to handle this situation?

like image 394
Syed Aslam Avatar asked Aug 25 '10 12:08

Syed Aslam


2 Answers

Overwrite Devise::SessionsController like this:

class SessionsController < Devise::SessionsController
  respond_to :html
  def destroy
    super
    reset_session
  end
end

Don't forget to move the devise views to the right place (views/devise/sessions to views/sessions) and modify the devise route to point to your controller. For example:

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

See the devise docs on github for more details or the link posted by Bill.

like image 139
mio Avatar answered Nov 02 '22 02:11

mio


I believe you'd have to over ride the devise controllers, there's a good post here on that:

Devise, CanCan and customizing devise controllers

like image 26
wkhatch Avatar answered Nov 02 '22 02:11

wkhatch