Pardeep Saini
Pardeep Saini

Reputation: 2102

How to destroy session and cookies on browser close in rails 4

I want to destroy user session and expire cookies whenever i close the browser. To expire cookies i try to create cookies without expiration time but not work.

EDIT :

cookies[:test] = {value: "test123", domain: :all}

I create this cookie and i want when i close the broswer , the is not available there . and when user log in i set current user with session (session[:user_id= @user.id) and I want when I close the browser , session[:user_id] should be null.

Upvotes: 0

Views: 1312

Answers (1)

Mr H
Mr H

Reputation: 5304

Just a quick suggestion:

I think if you use something like AngularJS or even jQuery, then you can fire a trigger when browser about to close to trigger a function to remove the cookies for you.

Regarding the Sessions you can use the same theory only you need to trigger Ajax as Session variables can be removed by Rails.

Upvotes: 1

Related Questions