# CGI and Webrick

**URL:** <https://rubytalk.org/t/cgi-and-webrick/8387>\
**Category:** ruby-talk\
**Created:** [3 October 2003 20:13 UTC](https://rubytalk.org/t/cgi-and-webrick/8387 "2003-10-03T20:13:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Giddings1](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@Ben\_Giddings1](https://rubytalk.org/u/Ben_Giddings1)\
**Post date:** [3 October 2003 20:13 UTC](https://rubytalk.org/t/cgi-and-webrick/8387/1 "2003-10-03T20:13:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard1](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Ara.T.Howard1](https://rubytalk.org/u/Ara.T.Howard1)\
**Post date:** [4 October 2003 00:52 UTC](https://rubytalk.org/t/cgi-and-webrick/8387/2 "2003-10-04T00:52:45Z")

</div>

> 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:

| joe | 574-86-5022 |
| jane | 574-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](mailto: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’  
> > ====================================

---

<div class="post-metadata">

**Author:** ![John\_Long2](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@John\_Long2](https://rubytalk.org/u/John_Long2)\
**Post date:** [4 October 2003 01:10 UTC](https://rubytalk.org/t/cgi-and-webrick/8387/3 "2003-10-04T01:10:23Z")

</div>

> - 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](http://modruby.net/ml/archive/modruby/200309.month/952.html)

> **···**
>
> * * *
> 
> John Long  
> [www.wiseheartdesign.com](http://www.wiseheartdesign.com)
