Class: Array
Instance Method Summary collapse
-
#to_param ⇒ Object
Calls
to_paramon all its elements and joins the result with slashes. -
#to_query(key) ⇒ Object
Converts an array into a string suitable for use as a URL query string, using the given
keyas the param name.
Instance Method Details
#to_param ⇒ Object
Calls to_param on all its elements and joins the result with slashes. This is used by url_for in Action Pack.
32 33 34 |
# File 'lib/ext_core/query.rb', line 32 def to_param collect { |e| e.to_param }.join '/' end |
#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.
['Ruby', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Ruby&hobbies%5B%5D=coding"
6 7 8 9 |
# File 'lib/ext_core/array.rb', line 6 def to_query(key) prefix = "#{key}[]" collect { |value| value.to_query(prefix) }.join '&' end |