diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext/array/conversions.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/conversions.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index b7d4434e85..c828e84112 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -29,6 +29,15 @@ module ActiveSupport #:nodoc: join '/' end + # Converts an array into a string suitable for use as a URL query string, using the given <tt>key</tt> as the + # param name. + # + # ==== Example: + # ['Rails', 'coding'].to_query('hobbies') => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding" + def to_query(key) + collect { |value| value.to_query("#{key}[]") } * '&' + end + def self.included(base) #:nodoc: base.class_eval do alias_method :to_default_s, :to_s |