instance method
to_query
Ruby on Rails edge
Since v3.0.20Signature
to_query(key)
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"
Parameters
-
keyreq
Source
# File activesupport/lib/active_support/core_ext/object/to_query.rb, line 59
def to_query(key)
prefix = "#{key}[]"
if empty?
nil.to_query(prefix)
else
filter_map { |value|
next if (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
value.to_query(prefix)
}.join "&"
end
end
Defined in activesupport/lib/active_support/core_ext/object/to_query.rb line 59
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Array