From: Mark Hubbart Date: 2004-02-14T09:15:08+09:00 Subject: Re: cgi params in ruby On Feb 13, 2004, at 3:20 PM, Cere Davis wrote: > > Thank you both for helping me with this. > > > > This an error I am doomed to repeat I'm afraid because I understand > Hash.map and join systax (and didn't think it existed because ri > didn't list it under the Hash method). > > Hash.map would map to an array of key val pairs I suppose...where val > would be an array still. Then text fields get generated with
... > Then when I .join it's doing what? First of all, part of the problem you had, I think, is with the (IMHO) strange syntax that is used in the CGI module. When you call cgi.h1{"Title"}, or something like it, all it does is wrap it in the tag, so: cgi.h1{"Title"} #=> "

Title

" or: cgi.h1{"A " + cgi.bold{"Bold"} + " Title"} #=> "

A Bold Title

It just returns the string you gave it, but wrapped in a tag. So, if you do this: cgi.params.map{|key,value| cgi.text_field(key, val.to_s) + cgi.br } You end up getting an array of strings that each look something like this: '
' You finish it up by #joining the strings. cgi.params.map{|key,value| cgi.text_field(key, val.to_s) + cgi.br }.join Which gives you a string containing valid html markup, which can be passed (in a block) to cgi.form{}, etc. Also, calling aHash.map is functionally the same as calling aHash.to_a.map: it passes key/value pairs to the block. Cheers, Mark