Class: Array

Inherits:
Object show all
Defined in:
lib/office365/utils/to_query.rb

Instance Method Summary collapse

Instance Method Details

#to_paramObject

Calls to_param on all its elements and joins the result with slashes. This is used by url_for in Action Pack.



42
43
44
# File 'lib/office365/utils/to_query.rb', line 42

def to_param
  collect(&: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.

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


50
51
52
53
54
55
56
57
58
# File 'lib/office365/utils/to_query.rb', line 50

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

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