From: junderdown@... (Jason Underdown) Date: 2002-08-19T06:04:20+09:00 Subject: Re: Building tables dynamically with CGI class Thanks for your help Jim. The following code does exactly what I want: #!/usr/bin/ruby require 'cgi' cgi = CGI.new("html4Tr") table = [ ['00', '01', '02', '03'], ['10', '11', '12', '13'], ['20', '21', '22', '22'], ['30', '31', '32', '33'] ] cgi.out{ cgi.body{ cgi.table{ cgi.tr{cgi.th{"One"} + cgi.th{"Two"} + cgi.th{"Three"} + cgi.th{"Four"}} + table.collect{|row| cgi.tr{ row.collect{|item| cgi.td{ item } }.join } }.join } } } Jim Menard wrote in message news:... > junderdown@msn.com (Jason Underdown) writes: > > > I am fully aware of CGI#th. Maybe I didn't explain myself well > > enough. What I want to be able to do is something like the following > > code (which doesn't work): > > > > cgi.table('border'=>'1') { > > cgi.tr { cgi.th{"ID"} + cgi.th{"First"} + cgi.th{"Last"} } + > > rows.collect { |row| > > cgi.tr { > > row.collect { |item| > > cgi.td { item } > > } > > } > > } > > } > > > > My previous code posting works, but notice that since the header row > > gets generated by the same loop which creates the table body, the > > CGI#td method is used to generate the header cells instead of CGI#th. > > Change > > > row.collect { |item| > > cgi.td { item } > > } > > to > > > row.collect { |item| > > cgi.td { item } > > }.join("\n") > > because the value of the block needs to be a single string. > > Jim