rob
May 22nd, 2005, 04:23 PM
If you want to iterate through form variables, both GET and POST, you can use this little piece of code:
params.each do | field, value |
# use field and value variables however you want here
tmsg << field.to_s.capitalize << " - " << value.to_s << "\n"
end
In the case above, I'm assembling a variable called tmsg with the form variables sent to this script. In addition, I'm capitalizing the first letter of the field name.
Note I'm not using the traditional key, val approach, because I think field and value are more descriptive. Sure, its a few more characters to type, but I think anytime you can be more descriptive in programming, the better.
Rob
params.each do | field, value |
# use field and value variables however you want here
tmsg << field.to_s.capitalize << " - " << value.to_s << "\n"
end
In the case above, I'm assembling a variable called tmsg with the form variables sent to this script. In addition, I'm capitalizing the first letter of the field name.
Note I'm not using the traditional key, val approach, because I think field and value are more descriptive. Sure, its a few more characters to type, but I think anytime you can be more descriptive in programming, the better.
Rob