From: Cere Davis Date: 2004-02-14T09:44:55+09:00 Subject: Re: cgi params in ruby I agree with you about the cgi syntax strangeness. If you want to hand enter tag syntax you have to someone splice it in the cgi object instance and this sort of seems like to heavy of a burned to put on the end user who just wants to write some simple code. Maybe it's just my ignorance but I've found this package to be pretty inflexible. related to that actually... I wanted to just print labels before the text_field statements so that one can see the title of the text field that they are filling in. My intuition would be to just do: cgi.params.map {|key, val| cgi.print key + cgi.print " :" + cgi.text_field(key, val.to_s) + cgi.br }.join + # and join the result before moving on cgi.submit("Okey Dokey?") But noooo. It fails. Sorry for being a doofus but what am I doing wrong now? Thanks for the explanation below BTW. I get it now. > 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 > > >