module ActionDispatch::Http::Parameters

Public Instance Methods

parameters() click to toggle source

Returns both GET and POST parameters in a single hash.

# File lib/action_dispatch/http/parameters.rb, line 8
def parameters
  @env["action_dispatch.request.parameters"] ||= begin
    params = request_parameters.merge(query_parameters)
    params.merge!(path_parameters)
    encode_params(params).with_indifferent_access
  end
end
Also aliased as: params
params()
Alias for: parameters
path_parameters() click to toggle source

Returns a hash with the parameters used to form the path of the request. Returned hash keys are strings:

{'action' => 'my_action', 'controller' => 'my_controller'}

See symbolized_path_parameters for symbolized keys.

# File lib/action_dispatch/http/parameters.rb, line 34
def path_parameters
  @env["action_dispatch.request.path_parameters"] ||= {}
end
symbolized_path_parameters() click to toggle source

The same as path_parameters with explicitly symbolized keys.

# File lib/action_dispatch/http/parameters.rb, line 24
def symbolized_path_parameters
  @symbolized_path_params ||= path_parameters.symbolize_keys
end

Private Instance Methods

encode_params(params) click to toggle source

TODO: Validate that the characters are UTF-8. If they aren't, you'll get a weird error down the road, but our form handling should really prevent that from happening

# File lib/action_dispatch/http/parameters.rb, line 47
def encode_params(params)
  return params unless "ruby".encoding_aware?

  if params.is_a?(String)
    return params.force_encoding("UTF-8").encode!
  elsif !params.is_a?(Hash)
    return params
  end

  params.each do |k, v|
    case v
    when Hash
      encode_params(v)
    when Array
      v.map! {|el| encode_params(el) }
    else
      encode_params(v)
    end
  end
end
normalize_parameters(value) click to toggle source

Convert nested Hash to HashWithIndifferentAccess

# File lib/action_dispatch/http/parameters.rb, line 69
def normalize_parameters(value)
  case value
  when Hash
    h = {}
    value.each { |k, v| h[k] = normalize_parameters(v) }
    h.with_indifferent_access
  when Array
    value.map { |e| normalize_parameters(e) }
  else
    value
  end
end