Skip to content

Instantly share code, notes, and snippets.

@charlie
Created January 11, 2011 07:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlie/774142 to your computer and use it in GitHub Desktop.
Save charlie/774142 to your computer and use it in GitHub Desktop.
def hash_to_params(hash)
hash.keys.inject("") do |qs, key|
qs << "&" unless qs.blank?
qs << if Array === hash[key]
k = CGI.escape(key.to_s)
hash[key].map { |value| "#{k}=" << CGI.escape(value.to_s) }.join("&")
else
CGI.escape(key.to_s) << "=" << CGI.escape(hash[key].to_s)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment