decode_www_form

decode_www_form(str, enc=Encoding::UTF_8)
Class Public methods

Decode URL-encoded form data from given str.

This decodes application/x-www-form-urlencoded data and returns array of key-value array. This internally uses ::decode_www_form_component.

charset hack is not supported now because the mapping from given charset to Ruby's encoding is not clear yet. see also www.w3.org/TR/html5/syntax.html#character-encodings-0

This refers www.w3.org/TR/html5/forms.html#url-encoded-form-data

ary = ::decode_www_form(âa=1&a=2&b=3â) p ary #=> [['a', '1'], ['a', '2'], ['b', '3']] p ary.assoc('a').last #=> '1' p ary.assoc('b').last #=> '3' p ary.rassoc('a').last #=> '2' p Hash # => {âaâ=>â2â, âbâ=>â3â}

See ::decode_www_form_component, ::encode_www_form

doc_ruby_on_rails
2015-06-10 13:02:18
Comments
Leave a Comment

Please login to continue.