Object
Rack middleware for parsing POST/PUT body data into nested parameters
supported content type
# File lib/rack/contrib/nested_params.rb, line 21 def call(env) if form_vars = env[FORM_VARS] env[FORM_HASH] = parse_query_parameters(form_vars) elsif env[CONTENT_TYPE] == URL_ENCODED post_body = env[POST_BODY] env[FORM_INPUT] = post_body env[FORM_HASH] = parse_query_parameters(post_body.read) post_body.rewind if post_body.respond_to?(:rewind) end @app.call(env) end
the rest is nabbed from Rails ##
# File lib/rack/contrib/nested_params.rb, line 35 def parse_query_parameters(query_string) return {} if query_string.nil? or query_string.empty? pairs = query_string.split('&').collect do |chunk| next if chunk.empty? key, value = chunk.split('=', 2) next if key.empty? value = value.nil? ? nil : CGI.unescape(value) [ CGI.unescape(key), value ] end.compact UrlEncodedPairParser.new(pairs).result end
Generated with the Darkfish Rdoc Generator 2.