From: dmcnulty@... (Dan McNulty) Date: 2002-02-19T22:38:32+09:00 Subject: Re: CGI::Session problems Yes thank you for pointing that out. Along with a couple other changes, my test code now works. It does seem that you MUST use the ..close method anytime the session is accessed. Like the FAQ says :) Here is the fixed test code: def getsession(cgi) sess = CGI::Session.new(cgi, "session_key" => "a_test", "prefix" => "rubysess.") if sess["junk"]==nil puts "A new session" sess["junk"]=123 sess.close else puts "An existing session" sess["junk"]=sess["junk"].to_i + 1 puts sess["junk"] sess.close end return sess end Everytime I refresh the page, sess["junk"] increments just like it should. -- Dan Javier Fontan wrote in message news:<0202151700271J.03556@pc3d.cesga.es>... > Hello > > I think that this part f mod_ruby FAQ should help you > > --8<---- > CGI::Session does not work. > > On mod_ruby, CGI::Session is not closed automatically, so you should close it > explicitly.session = CGI::Session.new(...) > begin > ... > ensure > session.close > end > > This problem is not CGI::Session specific. You should close files etc too. > ---->8-- > > Bye > > On Fri 15 Feb 2002 17:00, you wrote: > > Argh! > > > > I am trying to using CGI:Session (with Apache & mod_ruby) and meeting > > no success. I have read what little there is about sessions in the > > two books I have, and scoured the 'net for examples (and found a few). > > > > The code I am using is like this: > > > > def getsession(cgi) > > if $sess == nil then > > $sess = CGI::Session.new(cgi, > > "session_key" => "a_test", > > "prefix" => "rubysess.") > > end > > return $sess > > end > > > > cgi = CGI.new > > sess = getsession(cgi) > > if sess["junk"] != nil > > puts "An existing session" > > puts Marshal.load(sess["junk"]) > > sess.update > > else > > puts "A new session" > > sess["junk"]=123 > > end > > > > The function getsession() is defined in a loaded file. > > > > The problem is that sess["junk"] is always nil, like session isn't > > being stored or restored. > > > > I would really love a simple example of this working under mod_ruby. > > I think perhaps mod_ruby is whacking my "cgi" object after every run. > > Since I need the session for variable persistance, this is not a good > > thing. > > > > Thanks for any help! > > > > -- Dan