From: Justin Collins Date: 2008-03-18T11:14:55+09:00 Subject: Re: CGI and Methods?? 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\n\nCommSpeed Log > Search\n\n\n" > puts "

No DHCP Log Results Found!

" > puts "\n\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