Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8343

Show
Ignore:
Timestamp:
12/09/07 22:12:07 (5 months ago)
Author:
bitsweat
Message:

Move #to_query methods where they ought to belong. Closes #10395 [Chu Yeow]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/core_ext/array/conversions.rb

    r8340 r8343  
    2828        def to_param 
    2929          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}[]") } * '&' 
    3039        end 
    3140 
  • trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb

    r8202 r8343  
    44require 'builder' 
    55require 'xmlsimple' 
    6  
    7 # Extensions needed for Hash#to_query 
    8 class Object 
    9   def to_param #:nodoc: 
    10     to_s 
    11   end 
    12  
    13   def to_query(key) #:nodoc: 
    14     "#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}" 
    15   end 
    16 end 
    17  
    18 class Array 
    19   def to_query(key) #:nodoc: 
    20     collect { |value| value.to_query("#{key}[]") } * '&' 
    21   end 
    22 end 
    236 
    247# Locked down XmlSimple#xml_in_string 
     
    10184        end 
    10285 
     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" 
    10393        def to_query(namespace = nil) 
    10494          collect do |key, value| 
  • trunk/activesupport/lib/active_support/core_ext/object.rb

    r7719 r8343  
     1require 'active_support/core_ext/object/conversions' 
    12require 'active_support/core_ext/object/extending' 
    23require 'active_support/core_ext/object/instance_variables'