Syed Aslam
Syed Aslam

Reputation: 8807

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?

Upvotes: 9

Views: 12110

Answers (2)

mio
mio

Reputation: 586

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.

Upvotes: 14

wkhatch
wkhatch

Reputation: 2741

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

Upvotes: 1

Related Questions