instance method to_query

Ruby on Rails 2.2.3

Since v2.2.3 Last seen in v2.3.18

Available 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).

Example:

{ :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

namespace opt = nil
Source
# File activesupport/lib/active_support/core_ext/hash/conversions.rb, line 107
        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 107 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::CoreExtensions::Hash::Conversions

Type at least 2 characters to search.

↑↓ navigate · open · esc close