views:

84

answers:

3

hello , 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 didnt work. how can i clear all the sessions that am using in my system each time i restart my server?

+1  A: 

To clear all the sessions use reset_session

Salil
A: 

If you are storing your sessions in a db then

rake db:sessions:clear
Anand
+1  A: 

Firstly, nil is not == false, however, nil evaluates to false. Try it yourself if you do not believe:

irb(main):001:0> nil == false
=> false
irb(main):002:0> nil == nil
=> true

Which ofcourse means:

irb(main):003:0> false.nil?
=> false

You can clean up your code in the following manner as it seems like @firsttime is never set to true anywhere.

unless session[:visited]
  session[:visited] = true
  initglobals
end

Finally, rake tmp:sessions:clear will only work if you are using ActiveRecordStore, if you are using CookieStore (which is the default). Then you will need to clean your cookies, or use reset_session.

Omar Qureshi