Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I clear all rails sessions?

Here is my code:

if session[:firsttimestart].nil?  else   @firsttime = false end  if @firsttime == true   initglobals() end session[:firsttimestart]=false 

The problem is when I turn off the server and come back to the application, the session[:firsttimestart] is still false. It somehow stores this variable in my system without an expiration date so the iniglobals() is not called. I tried to use rake tmp:clear and it didn't work. How can I clear all the sessions that am using in my system each time I restart my server?

like image 537
fenec Avatar asked Jun 19 '10 04:06

fenec


People also ask

How do I delete a session in Rails?

To clear the whole thing use the reset_session method in a controller. Resets the session by clearing out all the objects stored within and initializing a new session object.

Where are sessions stored in Rails?

Rails store it in server side. Session is saved in server side like key value pair (like json object)

What are Rails sessions?

Rails session is only available in controller or view and can use different storage mechanisms. It is a place to store data from first request that can be read from later requests. Following are some storage mechanism for sessions in Rails: ActionDispatch::Session::CookieStore - Stores everything on the client.

What is session and cookies in Rails?

Cookies, Sessions and Flashes are three special objects that Rails gives you in which each behave a lot like hashes. They are used to persist data between requests, whether until just the next request, until the browser is closed, or until a specified expiration has been reached.


2 Answers

Whether it's DB or cookie store, use rake tmp:sessions:clear

like image 152
Yevgeniy Avatar answered Oct 02 '22 17:10

Yevgeniy


If you are storing your sessions in a db then

rake db:sessions:clear 
like image 32
Anand Shah Avatar answered Oct 02 '22 16:10

Anand Shah