mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Improved docs for Hash#to_param method
This commit is contained in:
@@ -34,12 +34,11 @@ end
|
||||
class Hash
|
||||
# Converts a hash into a string suitable for use as a URL query string. An optional <tt>namespace</tt> can be
|
||||
# passed to enclose the param names (see example below). The string pairs "key=value" that conform the query
|
||||
# string are sorted lexicographically in ascending order.
|
||||
# string are sorted lexicographically in ascending order. This method is also aliased as <tt>to_query</tt>.
|
||||
#
|
||||
# ==== Examples
|
||||
# { :name => 'David', :nationality => 'Danish' }.to_param # => "name=David&nationality=Danish"
|
||||
#
|
||||
# { :name => 'David', :nationality => 'Danish' }.to_query('user') # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
|
||||
# { :name => 'David', :nationality => 'Danish' }.to_param('user') # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
|
||||
def to_param(namespace = nil)
|
||||
collect do |key, value|
|
||||
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
||||
|
||||
Reference in New Issue
Block a user