instance method
to_query
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
to_query(namespace = nil)
Converts a hash into a string suitable for use as a URL query string. An optional namespace can be passed to enclose the param names (see example below).
Examples
{ :name => 'David', :nationality => 'Danish' }.to_query # => "name=David&nationality=Danish"
{ :name => 'David', :nationality => 'Danish' }.to_query('user') # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
Parameters
-
namespaceopt = nil
Source
# File activesupport/lib/active_support/core_ext/hash/conversions.rb, line 98
def to_query(namespace = nil)
collect do |key, value|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
end.sort * '&'
end
Defined in activesupport/lib/active_support/core_ext/hash/conversions.rb line 98
· View on GitHub
· Improve this page
· Find usages on GitHub