CGI and Webrick

Hey all,

I’ve just started poking at three Ruby tools I haven’t yet used: DBI,
Webrick, and CGI, and have a few questions:

  • Is there good documentation for these somewhere? The distribution site
    for DBI has one page listing methods for some of the objects, but not
    others. For example, DBI::Row doesn’t seem to be documented at all.
    Webrick seems about the same, there are some quick examples, but no API
    documentation I could find.

  • Is there a way to get CGI to simply generate HTML? I managed to get it
    to stop prompting me to set variables using:

echo | ruby my_cgi_using_prog.rb

But then it throws on content-type headers, which I don’t want in my output.

  • Does anybody have experience connecting Webrick and CGI? Any tips, pointers?

Ben

Hey all,

I’ve just started poking at three Ruby tools I haven’t yet used: DBI,
Webrick, and CGI, and have a few questions:

  • Is there good documentation for these somewhere? The distribution site
    for DBI has one page listing methods for some of the objects, but not
    others. For example, DBI::Row doesn’t seem to be documented at all.
    Webrick seems about the same, there are some quick examples, but no API
    documentation I could find.

  • Is there a way to get CGI to simply generate HTML? I managed to get it
    to stop prompting me to set variables using:

echo | ruby my_cgi_using_prog.rb

even better (if you want to test input parameters) is

~ > cat input
key=value
a=b

ruby my_cgi_using_prog.rb < input

if no values

ruby my_cgi_using_prog.rb < /dev/null

if you want to generate html - check out amrita or misen.

eg.

----CUT----
#!/usr/bin/env ruby
require ‘amrita/template’

template = Amrita::TemplateText.new <<-html

html

data = Hash[
:rows => [
{:name => ‘joe’, :ssn => ‘574-86-5022’},
{:name => ‘jane’, :ssn => ‘574-86-5021’},
]
]

template.expand STDOUT, data

END

OUTPUT:

joe574-86-5022
jane574-86-5021
----CUT----

it’s powerfull.

-a

···

On Sat, 4 Oct 2003, Ben Giddings wrote:

But then it throws on content-type headers, which I don’t want in my output.

  • Does anybody have experience connecting Webrick and CGI? Any tips, pointers?

Ben

====================================

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@noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
The difference between art and science is that science is what we understand
well enough to explain to a computer. Art is everything else.
– Donald Knuth, “Discover”
~ > /bin/sh -c ‘for lang in ruby perl; do $lang -e “print "\x3a\x2d\x29\x0a"”; done’
====================================

  • Is there a way to get CGI to simply generate HTML? I managed to get it
    to stop prompting me to set variables using

CGI prompts you for variables because it has detected that you aren’t
running it as a cgi script or on mod_ruby. It looks in your environment
variables to determine how it is being run. If you want to set up your
environment variables so that cgi behaves as if it is being run on apache
see this link:

http://modruby.net/ml/archive/modruby/200309.month/952.html

···

John Long
www.wiseheartdesign.com