Module | URI |
In: |
lib/standard/facets/uri/query.rb
lib/standard/facets/uri/cgi_escape.rb lib/standard/facets/uri/decode.rb lib/standard/facets/uri/parameters.rb lib/standard/facets/uri.rb |
KEY_VALUE_SEPARATOR | = | ";" |
We cannot send nested hash as a param in HTTP requests. For example, when we would like to send something like this:
{:key => "value", :nested => {:nest => "value"}}
It would be (or should be) mapped like this:
/url/?key=value&nested=%7B%3Anest%3D%3E%5C%22value%5C%22%7D
Doesn’t look to good ;) However there is a simple way to convert a nested hash into a params acceptable form. We can convert it to a form, that can be mapped into params like this:
/url/?key=value&nested[nest]=value
Here is method to convert any nested hash to a “one level” equivalent:
@author Maciej Mensfeld
Allows for taking a hash and turning it into URI/CGI params Since 1.8.x does not have ordered hashes the params might not be ordered.
@todo URI.parameters needs URI escaping.
@author Matt Kirk
Given a hash with parameter/value pairs construct a standard query string.
URI.hash_to_query(:a => 1, :b => 2) #=> "a=1;b=2"
Extend the basic query string parser provided by the cgi module. converts single valued params (the most common case) to objects instead of arrays
Returns hash of parameters, contains arrays for multivalued parameters (multiselect, checkboxes , etc).
If no query string is provided (nil or "") returns an empty hash.
Get a uri and a hash of parameters. Inject the hash values as parameters in the query sting path. Returns the full uri.
uri - the uri to filter (String) parameter - hash of parameters to update
Returns the full updated query string.
@todo Optimize this method.
Gets the request uri, injects extra parameters in the query string and returns a new uri. The request object is not modified. There is always a qs string so an extra test is skipped.
TODO: find a better name?