Browse files

reorganizes the RDoc of Hash#to_param

  • Loading branch information...
1 parent 89ecc0a commit a0d7247d1509762283c61182ad82c2eed8d54757 @fxn fxn committed Mar 7, 2011
Showing with 14 additions and 6 deletions.
  1. +14 −6 activesupport/lib/active_support/core_ext/object/to_param.rb
View
20 activesupport/lib/active_support/core_ext/object/to_param.rb
@@ -32,13 +32,21 @@ def to_param
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. This method is also aliased as <tt>to_query</tt>.
+ # Returns a string representation of the receiver suitable for use as a URL
+ # query string:
#
- # ==== Examples
- # { :name => 'David', :nationality => 'Danish' }.to_param # => "name=David&nationality=Danish"
- # { :name => 'David', :nationality => 'Danish' }.to_param('user') # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
+ # {:name => 'David', :nationality => 'Danish'}.to_param
+ # # => "name=David&nationality=Danish"
+ #
+ # An optional namespace can be passed to enclose the param names:
+ #
+ # {:name => 'David', :nationality => 'Danish'}.to_param('user')
+ # # => "user[name]=David&user[nationality]=Danish"
+ #
+ # The string pairs "key=value" that conform the query string
+ # are sorted lexicographically in ascending order.
+ #
+ # This method is also aliased as +to_query+.
def to_param(namespace = nil)
collect do |key, value|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)

0 comments on commit a0d7247

Please sign in to comment.