Tony De wrote:
> Hi all,
>
> I'm trying my hand at scripting cgi in ruby.  At the same time I'm
> looking at Rails.  So far I love ruby.  Still reserving comments on
> Rails.  I have a question though.  When coding a cgi script, is it
> possible to have methods as I would say in a n my_app.rb or rails app?
> Below is a script I'm working on to provide a web interface to our
> syslog servers logs for our tech support dept.  I would like to DRY this
> up a bit.  I'm repeating entirely too much code.  I would welcome not
> only a response to my question, but any other suggestions/criticism to
> aid me in my learning process.  Thank you very much.
>
> tonyd
>   

Writing code using the CGI library is just like any other Ruby code, so 
you can have any methods, classes, or other code that you want.

>     puts "Content-type:
> text/plain\r\n\r\n<HTML>\n<HEAD>\n<TITLE>CommSpeed Log
> Search</TITLE>\n</HEAD>\n<BODY>\n"
>     puts "<h1>No DHCP Log Results Found!</h1>"
>     puts "</BODY>\n</HTML>\n"
>                 exit

The CGI library does this kind of HTML work for you. See the example in 
about the middle of the page here:
http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/classes/CGI.html
and the documentation here:
http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/classes/CGI/HtmlExtension.html



-Justin