Forum: Ruby on Rails How do you delete a session variable?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B780ee0ee1480454a85df58536702f63?d=identicon&s=25 Alder Green (Guest)
on 2006-05-18 11:58
(Received via mailing list)
Hi

Let's say we set session[:foo] = 'bar'. Now we want to remove the :foo
key completely. How do you do that?

Appearantly, session is a CGI::Session [1] instance, so it doesn't
have #delete like Hash. I tried:

session[:foo] = nil

But then debug(session) shows an empty :foo key. I'd like to remove
that key, as my session is already pretty crowded. Is it possible?

--
-Alder

[1] http://ruby-doc.org/core/classes/CGI/Session.html
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Richard Williams (Guest)
on 2006-05-18 16:46
(Received via mailing list)
On Thursday, May 18, 2006, at 11:56 AM, Alder Green wrote:
>But then debug(session) shows an empty :foo key. I'd like to remove
>that key, as my session is already pretty crowded. Is it possible?
>
>--
>-Alder
>
>[1] http://ruby-doc.org/core/classes/CGI/Session.html
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails


Will session.delete["foo"] work?
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-05-18 17:02
(Received via mailing list)
see http://wiki.rubyonrails.org/rails/pages/HowtoWorkW... for
your
answer.


On 18 May 2006 14:44:35 -0000, Richard Williams <
B780ee0ee1480454a85df58536702f63?d=identicon&s=25 Alder Green (Guest)
on 2006-05-18 17:26
(Received via mailing list)
On 18 May 2006 14:44:35 -0000, Richard Williams
<devlists-rubyonrails@devlists.com> wrote:
> >session[:foo] = nil
> >Rails@lists.rubyonrails.org
> >http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
> Will session.delete["foo"] work?

No, since the object returned by #session isn't a Hash - it's a
Hash-like instance of CGI::Session. So it doesn't have the various
Hash intance methods. It does have a #hash method btw, but it does
something entirely different ("Delete the session from storage. Also
closes the storage.")
B780ee0ee1480454a85df58536702f63?d=identicon&s=25 Alder Green (Guest)
on 2006-05-18 17:29
(Received via mailing list)
On 5/18/06, Chris Hall <christopher.k.hall@gmail.com> wrote:
>
> see
> http://wiki.rubyonrails.org/rails/pages/HowtoWorkW...
> for your answer.

"
Completely removing a previously-set key/value pair:
[not possible]
"

Ok, guess it's better than no answer :)

Thanks.
This topic is locked and can not be replied to.