0

My controller tries to set the session value to nil. Within the controller, it works, but then we I reload the browser (not quit), the session value comes back?

How can I keep it cleared out and empty? Is it possible the browser still stores that session even though I set it = nil?

5
  • Are you calling session['value]' = nil or session = nil? Commented Jun 18, 2011 at 15:30
  • the first -- I don't want to kill the other session variables.... Commented Jun 18, 2011 at 22:25
  • Then the code you provided should be correct. Are you sure it is being called? Commented Jun 19, 2011 at 3:13
  • yes, I step through it in the debugger... :( Commented Jul 27, 2011 at 1:25
  • 1
    I am having this same problem when I set an existing session to a new value. On reload the original session value is loading. I think that Kelvin is correct about the new value not making it to the browser, but i don't know why that would be the case. @Angela, did you ever find an answer to this problem Commented May 23, 2012 at 18:18

2 Answers 2

1

Setting the variable to nil keeps the session. Try to call

reset_session 

in your controller to get rid of the whole session.

Nonetheless, even after setting the value to nil, it should not come up in your next request. Make sure you are not setting it back, e.g. in a before_filter.

Sign up to request clarification or add additional context in comments.

2 Comments

I want to keep the session, just that one value. I use it to check if the person coming came by clicking on an invitation link
In that case your code is correct, indeed. There must be something else wrong. Could you please provide additional information, such as - Which session storage do you use (Cookie or ActiveRecord) - Controller code setting value to nil - Controller code for checking the value in next request
0

If you're using cookie store for the session, maybe the changed session isn't making it to the browser. If this is the case, the browser still has the old value in the cookie. When the page is reloaded, the browser will send the cookie to rails, which will restore the old value.

It's hard to say more without seeing your controller action.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.