Method: Array#to_query

Defined in:
lib/openstack/core_ext/to_query.rb

#to_query(key) ⇒ Object

Converts an array into a string suitable for use as a URL query string, using the given key as the param name.

['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"


48
49
50
51
52
53
54
55
56
# File 'lib/openstack/core_ext/to_query.rb', line 48

def to_query(key)
  prefix = "#{key}[]"

  if empty?
    nil.to_query(prefix)
  else
    collect { |value| value.to_query(prefix) }.join '&'
  end
end