Changeset 8343
- Timestamp:
- 12/09/07 22:12:07 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/core_ext/array/conversions.rb
r8340 r8343 28 28 def to_param 29 29 join '/' 30 end 31 32 # Converts an array into a string suitable for use as a URL query string, using the given <tt>key</tt> as the 33 # param name. 34 # 35 # ==== Example: 36 # ['Rails', 'coding'].to_query('hobbies') => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding" 37 def to_query(key) 38 collect { |value| value.to_query("#{key}[]") } * '&' 30 39 end 31 40 trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb
r8202 r8343 4 4 require 'builder' 5 5 require 'xmlsimple' 6 7 # Extensions needed for Hash#to_query8 class Object9 def to_param #:nodoc:10 to_s11 end12 13 def to_query(key) #:nodoc:14 "#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"15 end16 end17 18 class Array19 def to_query(key) #:nodoc:20 collect { |value| value.to_query("#{key}[]") } * '&'21 end22 end23 6 24 7 # Locked down XmlSimple#xml_in_string … … 101 84 end 102 85 86 # Converts a hash into a string suitable for use as a URL query string. An optional <tt>namespace</tt> can be 87 # passed to enclose the param names (see example below). 88 # 89 # ==== Example: 90 # { :name => 'David', :nationality => 'Danish' }.to_query # => "name=David&nationality=Danish" 91 # 92 # { :name => 'David', :nationality => 'Danish' }.to_query('user') # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish" 103 93 def to_query(namespace = nil) 104 94 collect do |key, value| trunk/activesupport/lib/active_support/core_ext/object.rb
r7719 r8343 1 require 'active_support/core_ext/object/conversions' 1 2 require 'active_support/core_ext/object/extending' 2 3 require 'active_support/core_ext/object/instance_variables'