Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
CGI tables in Ruby

Posted by Milo (Milo), 1 June 2004
I've been trying to convert a script to run on a web server, and discovered that Ruby cgi scripts are as much of the devil as Perl ones. Any suggestions on how to make one thing work would be welcome.
The script normally produces an html table, as follows:

puts "<table border = 1>\n"

puts "<tr><td>switch summary info.</td><td> query id</td><td> subject id</td><td>percent identity</td><td>alignment length</td><td>mis-matches</td><td>gap openings</td><td>query start</td><td>query end</td><td>subject start</td><td>subject end</td><td>e-value</td><td>bit score</td></tr>\n"

switch_summary.each_value do |val|
               line = val.split(",").to_a
               print "<tr>"
               line.each do |l|
                                 print "<td>#{l}</td>"
               print "</tr>\n"
puts "</table>"

There may well be other faults with this code, but the main problem I have is converting it to use CGI. Can anyone suggest a rough way to do it?

Posted by admin (Graham Ellis), 1 June 2004
Is this just a snippet of code or the whole thing?   If it's the whole thing, then starting it off with
     puts "Content-type: text/html\n\n"
should work wonders (you may need to change the ruby location.

If, as I suspect, there's more to the question than that, can you let me know.  Thanks!

Posted by Milo (Milo), 1 June 2004
You are indeed correct - this is a small fragment of a script that I have placed here:
As many users won't have Ruby, won't want to install it, and will only want to examine one organism I plan to run the code as a CGI script allowing them to select their favourite organism (the same server runs a database with all the data already available) and view the output as a dynamically generated HTML table.
Currently, getting the output into that format is proving rather difficult.
This is my first attempt at any Ruby so it will look dodgy, but at least it works.

Posted by Milo (Milo), 2 June 2004
I've now found the solution - I was not aware of the difference between array.each and, so the following code does the trick:

cgi.h3 { "Results for #{genome}"} +
     cgi.table('BORDER' => '1') {
  { |val|
                       val.split(",").map { |l| {"#{l}"} }
                 } + "\n"


This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho