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.
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?
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 R. 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.
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?
I am trying to bring an Web App up in ruby 1.9.3 which worked flawlessly
in ruby 1.8.7.
On a side note: You should definitely think about using HTML templates
and meaningful variable names. I find the code above almost unreadable
with all the cryptic abbrevations and the mixture of programming logic
and HTML stuff.
It looks a bit like one of those early PHP scripts (well, at least you
wrote some comments).
Hi Marc
not absolutely: finally, I need valid HTML code, nothing more.
Preferably would be valid XHTML code, but as far as I know, creating
XHTML is not possible with ruby cgi. For ruby 1.8.7 there was a patch pablotron.org to create XHTML, but I could not find the
equivalent for ruby 1.9.3.
Instead of the collect iterator, I could probably use the each iterator,
but as far as I remember, this one drops even more unwanted garbage into
the HTML Text. So I might be better off with the collect iterator.
suomi
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.