I''m sorry if this is really dumb, but I can''t find the answer. How do I clear (or unset) a session variable? Not the whole session, just one item. I tried treating the session as a hash, but session.delete(:mykey) does not work. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I typically do session[:the_var] = nil someone please correct me if there''s a better way. On 3/30/07, Rick <rschumeyer-EkmVulN54Sk@public.gmane.org> wrote:> > > I''m sorry if this is really dumb, but I can''t find the answer. > > How do I clear (or unset) a session variable? Not the whole session, > just one item. > > I tried treating the session as a hash, but > session.delete(:mykey) > does not work. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
session[:key] = nil seems to be the accepted way of doing this. session is not just a hash, and if you look at the source, #delete takes no parameters and actually clears the entire session. A lot of people (including me) run into this, and I''m still not sure why it was done this way. What''s wrong with making session.clear (or session.empty) empty it out and keeping session.delete(:key) to work like a hash? The current implementation definitely violates the Principle of Least Surprise. Jason On 3/30/07, Dutch Rapley <dutch.rapley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I typically do > > session[:the_var] = nil > > someone please correct me if there''s a better way. > > On 3/30/07, Rick < rschumeyer-EkmVulN54Sk@public.gmane.org> wrote: > > > > > > I''m sorry if this is really dumb, but I can''t find the answer. > > > > How do I clear (or unset) a session variable? Not the whole session, > > just one item. > > > > I tried treating the session as a hash, but > > session.delete(:mykey) > > does not work. > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---