From: Ruby Ruby Date: 2012-06-11T20:40:31+09:00 Subject: Re: cgi class prints garbage in HTML output Hi everybody the correct (i.e. the code which creates the requested HTML code) ruby 1.9.3 code for the requested result looks like: NOTE: each ..collect do ... must be terminated by an ... end.join("") nf = rf.length # total number of fields to display noc = @sess["noc"].to_i nor = nf/noc # total number of rows to display ncta = (CHARS_TEXTAREA / noc).to_s # cols in the textarea if nrr == 1 # must be one single row @c.tablen("class"=>"ps") { "#{ (0..nor).collect do |rct| # field names @c.tr{ "#{ rf[rct*noc, noc].collect do |nf| # field name nt = @dbx.tat[nf].to_s # field type @sess["aeq"].include?(nf) ? nf = @sess["aeq"][nf] : nf = _(nf) @c.th("class"=>"tah") {"#{nf} (#{nt})"} end.join("") }" }+"\n"+ @c.tr{ # field content "#{ rf[rct*noc, noc].collect do |nf| # field name nt = @dbx.tat[nf].to_s # field type nr = rr[nf] # field value if nf.match(/date_(next|last)_action/) nr = Time.now.strftime("%Y-%m-%d") end nx = CGI::unescape(nr) nrta = ROWS_NEW_TEXTAREA.to_s cmds[nt].call(ncta, nrta, nf, nx, nr) end.join("") }" } end.join("") }"+"\n" } Ruby Ruby wrote in post #1064003: > Hi everybody > > I am trying to bring an Web App up in ruby 1.9.3 which worked flawlessly > in ruby 1.8.7. But sofar, I am stumbling from one failure to the next. > At some point it seems to me as if the cgi class would write everything > it gets hands on to the HTML output, which makes that the HTML output is > unusable, to say the least. > > Note that in the following ruby code snippet @c is the actual cgi-class. > > This is the code which generates the main HTML table (table3): > > > nf = rf.length # total number of fields to display > noc = @sess["noc"].to_i > nor = nf/noc # total number of rows to display > ncta = (CHARS_TEXTAREA / noc).to_s # cols in the textarea > if nrr == 1 # must be one single row > @c.tablen("class"=>"ps") { "#{ > (0..nor).collect { |rct| > # field names > @c.tr{ > "#{ rf[rct*noc, noc].collect { |nf| # field name > nt = @dbx.tat[nf].to_s # field type > @sess["aeq"].include?(nf) ? nf = @sess["aeq"][nf] : nf = _(nf) > @c.th("class"=>"tah") {"#{nf} (#{nt})"} > } > }" > }+"\n"+ > @c.tr{ > # field content > "#{ rf[rct*noc, noc].collect { |nf| # field name > nt = @dbx.tat[nf].to_s # field type > nr = rr[nf] # field value > if nf.match(/date_(next|last)_action/) > nr = Time.now.strftime("%Y-%m-%d") > end > nx = CGI::unescape(nr) > nrta = ROWS_NEW_TEXTAREA.to_s > cmds[nt].call(ncta, nrta, nf, nx, nr) > > } > }" > } > } > }"+"\n" > } > > > And this is the generated HTML code. Note that I manually inserted the > line feeds into the HTML text, to make it readable. In the original, all > is on one single line. > > > [" > [\"\", \"\", \" > \", \" > \", \" > \"]\n > [\"\", \"\", \"\", \"\", \"\"] > ", "[\"\", \"\", \"\", \"\", \"\"]\n[\"\", \"\", \"\", \"\", \"\"]", "[\"\", \"\", \"\", \"\"]\n[\"\", \"\", \"\", \"\"]"] >
task_name (text) class=\\\"tah\\\">actiony (text)date_start (date)date_end (date)period (int(4) unsigned)
> \\n > > \\n > name=\\\"date_start\\\" id=\\\"date_start\\\" onchange=\\\"ctx(this)\\\" > value=\\\"\\\" TYPE=\\\"text\\\">\\n > name=\\\"date_end\\\" id=\\\"date_end\\\" onchange=\\\"ctx(this)\\\" > value=\\\"\\\" TYPE=\\\"text\\\">\\n > name=\\\"period\\\" id=\\\"period\\\" onchange=\\\"ctx(this)\\\" > value=\\\"\\\" TYPE=\\\"text\\\">\\n
next_period (date) class=\\\"tah\\\">date_last_action (date) class=\\\"tah\\\">date_next_action (date) class=\\\"tah\\\">start_time (time) class=\\\"tah\\\">end_time (time)
class=\\\"v\\\"> id=\\\"next_period\\\" onchange=\\\"ctx(this)\\\" value=\\\"\\\" > TYPE=\\\"text\\\">\\n class=\\\"df\\\" name=\\\"date_last_action\\\" > id=\\\"date_last_action\\\" onchange=\\\"ctx(this)\\\" > value=\\\"2012-06-11\\\" TYPE=\\\"text\\\">\\n class=\\\"v\\\"> id=\\\"date_next_action\\\" onchange=\\\"ctx(this)\\\" > value=\\\"2012-06-11\\\" TYPE=\\\"text\\\">\\n class=\\\"v\\\"> id=\\\"start_time\\\" onchange=\\\"ctx(this)\\\" value=\\\"\\\" > TYPE=\\\"text\\\">\\n class=\\\"df\\\" name=\\\"end_time\\\" id=\\\"end_time\\\" > onchange=\\\"ctx(this)\\\" value=\\\"\\\" > TYPE=\\\"text\\\">\\n
class=\\\"tah\\\">task_address (text) class=\\\"tah\\\">task_comment (text) class=\\\"tah\\\">task_responsible (text) class=\\\"tah\\\">project (text)
class=\\\"v\\\">\\n class=\\\"v\\\">\\n class=\\\"v\\\">\\n class=\\\"v\\\">\\n
>
> > Has someone had such problems as well with ruby 1.9.3? I already > mentionned that the above ruby code worked fine in ruby 1.8.7. > What do I need to change to prohibit the multi-escaping of each item? > > Thanks very much for any idea. > > suomi -- Posted via http://www.ruby-forum.com/.