CGI and Webrick

B

Ben Giddings

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
 
A

Ara.T.Howard

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>
<body>
<table>
<tr id=rows>
<td id=name></td><td id=ssn></td>
</tr>
</table>
</body>
</html>
html

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

template.expand STDOUT, data

__END__

OUTPUT:

<html>
<body>
<table>
<tr>
<td>joe</td><td>574-86-5022</td>
</tr><tr>
<td>jane</td><td>574-86-5021</td>
</tr>
</table>
</body>
</html>
----CUT----


it's powerfull.

-a
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: (e-mail address removed)
| 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'
====================================
 
J

John W. Long

* Is there a way to get CGI to simply generate HTML? I managed to get it
to stop prompting me to set variables using <snip />

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top