views:

402

answers:

2

I can't seem to find it anywhere... How do you delete/destroy/reset user's session in rails? Not just one value but the whole thing.

A: 

Access the ActionController session hash and set the entry for that user to nil:

Example (from http://rails.learnhub.com/lesson/6372-action-controller-session):

class LoginsController < ApplicationController

  # "Delete" a login, aka "log the user out" 
  def destroy
    # Remove the user id from the session
    session[:current_user_id] = nil
    redirect_to root_url
  end

end
Kaleb Brasee
+5  A: 

To clear the whole thing use the reset_session method in a controller.

reset_session

Here's the documentation on this method: http://api.rubyonrails.org/classes/ActionController/Base.html#M000668

Resets the session by clearing out all the objects stored within and initializing a new session object.

Good luck!

Gdeglin