nko
03-02-2006, 05:41 PM
I've got a CGI script written in Ruby. I'm trying to iterate through
my POST data and do one thing if a given key has the word "line" in it
and another if it doesn't. Here's my code so far:
post.each {|x, y|
if x.to_s =~ "line"
puts ""
else
puts "<input type=\"hidden\" name=\"" + x.to_s + "\" value=\"" +
y.to_s + "\" />"
end
}
Running this script from the browser and filling in some dummy POST
data at the command line, it complains about that second line (the
=~):
shippingForm.rb:63:in `=~': type mismatch: String given (TypeError)
from shippingForm.rb:63
from shippingForm.rb:62:in `each'
from shippingForm.rb:62
Since I'm comparing a string to a string, I'm at a complete loss. Any ideas?
my POST data and do one thing if a given key has the word "line" in it
and another if it doesn't. Here's my code so far:
post.each {|x, y|
if x.to_s =~ "line"
puts ""
else
puts "<input type=\"hidden\" name=\"" + x.to_s + "\" value=\"" +
y.to_s + "\" />"
end
}
Running this script from the browser and filling in some dummy POST
data at the command line, it complains about that second line (the
=~):
shippingForm.rb:63:in `=~': type mismatch: String given (TypeError)
from shippingForm.rb:63
from shippingForm.rb:62:in `each'
from shippingForm.rb:62
Since I'm comparing a string to a string, I'm at a complete loss. Any ideas?