From: Szabolcs Szasz Date: 2002-10-09T02:54:03+09:00 Subject: Session stub & a bug (Was: Update on HTTP session handling in Ruby?) (Just for the record, in case another newbie tries to find something like this in the archive...) > Does this mean that the current cgi/session is just fine > now, or people gave up the quest for the Holy Grail? > (CGI::Session used to be a little handicapped compared > to e.g. PHP's, AFAIK.) I had constant problems with sessions (but that's just usual for me, having constant problems with things working fine for others. ;) ). 1. Minimal sessioned .rhtml page I could come up with: <% require 'cgi/session' session = CGI::Session.new( cgi = CGI.new('html4') ) begin session['var'] = 'xxx' # # You WILL use sessions from mod_ruby, so don't forget this # for closing it (ie. closing the session-file, by default). # # See: http://www.modruby.net/doc/faq.en.html#label:14 # ensure cgi.header # *NASTY* hack to flush stuff to actually make the # session live -- needed only for creating a session. # Any nicer way, please?? (I DO NOT want to # clutter my "main stuff" (above) with cgi.calls, as # I only need sessions, and conceptually, CGI has # nothing to do with that. I want a clean page...) session.close end %> 2. There is a fatal bug in cgi/session.rb (class FileStore): If you do not use or set any session[] variables, hitting reload on the page will kill the script (ruby 1.6.7): [Tue Oct 8 18:53:36 2002] [error] mod_ruby: error in ruby /usr/lib/ruby/1.6/cgi/session.rb:123:in `update': undefined method `each' for nil (NameError) from /usr/lib/ruby/1.6/cgi/session.rb:130:in `close' from /usr/lib/ruby/1.6/cgi/session.rb:81:in `close' from /tmp/index.rhtml.3335.0:11 from /usr/lib/ruby/1.6/apache/eruby-run.rb:112:in `load' from /usr/lib/ruby/1.6/apache/eruby-run.rb:112:in `run' from /usr/lib/ruby/1.6/apache/eruby-run.rb:78:in `handler' from ruby:0 The problem: FileStore.update assumes @hash is never nil, but FileStore.initialize does NOT initialize @hash if a file for the current session-ID already exists... Cheers, Sz.