Reputation: 4053
In Ruby on Rails :
suppose I am having session[:my_var] = 'my_val'
So here my question is :
Do we need to set session[:my_var]=nil
before user's sign-out?
or it will auto release the memory it has.
Upvotes: 5
Views: 8294
Reputation: 1869
If you have set up your authentication code properly, that should handle the release from memory. Here is how I did it in one of my apps:
#sessions_controller
def destroy
reset_session
redirect_to login_path, notice: 'Logged out'
end
Upvotes: 2
Reputation: 4404
Ruby on Rails doesn't know what you want to keep or not when a user signs-out.
Say for example you have a session[:language]
that is useful for every user, even anonymous ones. You wouldn't want to erase it to display the default language after the user has gone through the trouble of selecting one in particular.
So, delete the session objects you need to, like session[:user]=nil
and keep the rest. If you have a lot of them to delete, make yourself a logout helper.
If you know you can swipe the whole session, use the reset_session
like @adcosta said.
Upvotes: 5