On Wed, 16 Apr 2003, Brett H. Williams wrote:

<snip>
> It really felt like a bad hack, but a colleague (who did most of the rhtml)
> says that this is just how its done:  the parts of the program that interact
> directly with the web are just generally ugly.
>
> There are several ideas that come to mind to help.  Simply wrap some methods
> around creating hidden fields to manage data, or use a session ID and the
> Marshal module to write the state to disk.  Is there a framework that will
> help with this (and likely other related tasks)?
>
> However my real question is:  does something already exist that helps me
> with this?  I've looked through the RAA, and the closest thing I saw was
> borges, but my platform is Apache (not WEBrick).
>
> Realize I'm not very well versed in the proper terminology etc. so I may be
> missing some obvious things.  It may be that what I want is simple enough
> that no one has made a package, if so I guess we'll just write it.  But I
> just have this feeling that something this common has got to be part of a
> larger framework.
>
> Does anyone have any suggestions?


this is super simple, and works great :

http://raa.ruby-lang.org/list.rhtml?name=cgi-sess-pstore

it allows one to store arbitrary objects using cgi sessions.  sessions are
alot slicker than hidden fields, espcecially if you want to store more than
just strings - or data which is large - between page hits.

the session itself uses arbitrary objects in the way a hash does :

  key_object -> value_object

usages is as in

  require 'cgi'
  require 'cgi/session/pstore'

  cgi = CGI.new
  sessionn = CGI::Session.new(cgi, 'database_manager' => CGI::Session::PStore)

  key = String.new('some_key_object)
  value = ['can', 'be', 'most', 'anything']

  session[key] = value

  # cgi stuff

  session.update


you can download it from

  http://raa.ruby-lang.org/list.rhtml?name=cgi-sess-pstore

see an example program at

  http://eli.fsl.noaa.gov/ruby/class/0/cgi/session/pstore.cgi

it's an anoying little program which caches the current time as a Time object
and displays it every few seconds using meta-refresh - which is terrible but
illustrates the point. ;-)

there's a link there to view the source.

feel free to contact me with questions.

-a

--
  ====================================
  | Ara Howard
  | NOAA Forecast Systems Laboratory
  | Information and Technology Services
  | Data Systems Group
  | R/FST 325 Broadway
  | Boulder, CO 80305-3328
  | Email: ara.t.howard / fsl.noaa.gov
  | Phone:  303-497-7238
  | Fax:    303-497-7259
  ====================================