Training, Open Source computer languages

This is page http://www.wellho.net/forum/Programm ... -Ruby/CGI-tables-in-Ruby.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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>"
               end
               print "</tr>\n"
end
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?
Thanks!

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
     #!/usr/local/bin/ruby
     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:
http://www.genomics.ceh.ac.uk/~milo/switchfinder_general/
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
Graham,
I've now found the solution - I was not aware of the difference between array.each and array.map, so the following code does the trick:


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

Thanks,
Milo.



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

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho