class ActionController::Parameters

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/action_controller/metal/strong_parameters.rbs

class ActionController::Parameters
  def []: ((Symbol | String) key) -> String?
  def []=: (String key, String value) -> String
  
  type ActionController__Parameters_convert_hashes_to_parameters_value = String | Array[String] | nil | Hash
  
  def convert_hashes_to_parameters: ((String | Symbol) key, ActionController__Parameters_convert_hashes_to_parameters_value value) -> (String | nil | ActionController::Parameters)
  def convert_parameters_to_hashes: (String value, Symbol using) -> String
  def convert_value_to_parameters: (String? value) -> String?
  def initialize: (?Hash parameters, ?Hash logging_context) -> void
  def new_instance_with_inherited_permitted_status: (Hash hash) -> ActionController::Parameters
  def permitted_scalar?: (String value) -> true
  def permitted_scalar_filter: (ActionController::Parameters params, String permitted_key) -> untyped
  def slice: (*Array[String] keys) -> ActionController::Parameters
  def unpermitted_parameters!: (ActionController::Parameters params) -> nil
end

params # => “value”<br>params # => “value”
params = ActionController::Parameters.new(key: “value”)
:key or "key".
You can fetch values of ActionController::Parameters using either
runtime.
environment they should only be set once at boot-time and never mutated at
Please note that these options *are not thread-safe*. In a multi-threaded
# => ActionController::UnpermittedParameters: found unpermitted keys: a, b
params.permit(:c)
params = ActionController::Parameters.new(a: “123”, b: “456”)
ActionController::Parameters.action_on_unpermitted_parameters = :raise
# => #<ActionController::Parameters {} permitted: true>
params.permit(:c)
params = ActionController::Parameters.new(a: “123”, b: “456”)
params.permitted? # => true
params = ActionController::Parameters.new
ActionController::Parameters.permit_all_parameters = true
params.permitted? # => false
params = ActionController::Parameters.new
Examples:
* :raise to raise an ActionController::UnpermittedParameters exception.
unpermitted_parameters.action_controller topic and log at the DEBUG level.
* :log to emit an ActiveSupport::Notifications.instrument event on the
* false to take no action.
false otherwise. The values can be:
permitted are found. The default value is :log in test and development environments,
* action_on_unpermitted_parameters - Controls behavior when parameters that are not explicitly
permitted by default. The default is false.
* permit_all_parameters - If it’s true, all the parameters will be
It provides two options that controls the top-level behavior of new instances:
# => #<Person id: 1, name: “Francesco”, age: 22, role: “user”>
Person.first.update!(permitted)
permitted.permitted? # => true
permitted # => #<ActionController::Parameters {“name”=>“Francesco”, “age”=>22} permitted: true>
permitted = params.require(:person).permit(:name, :age)
})
}
role: “admin”
age: 22,
name: “Francesco”,
person: {
params = ActionController::Parameters.new({
as permitted and limit which attributes should be allowed for mass updating.
used to mark parameters as required. The latter is used to set the parameter
Provides two methods for this purpose: #require and #permit. The former is
and thus prevent accidentally exposing that which shouldn’t be exposed.
Allows you to choose which attributes should be permitted for mass updating
== Action Controller Parameters

def self.hook_into_yaml_loading # :nodoc:

:nodoc:
def self.hook_into_yaml_loading # :nodoc:
  # Wire up YAML format compatibility with Rails 4.2 and Psych 2.0.8 and 2.0.9+.
  # Makes the YAML parser call `init_with` when it encounters the keys below
  # instead of trying its own parsing routines.
  YAML.load_tags["!ruby/hash-with-ivars:ActionController::Parameters"] = name
  YAML.load_tags["!ruby/hash:ActionController::Parameters"] = name
end

def ==(other)

permitted flag.
Returns true if another +Parameters+ object contains the same content and
def ==(other)
  if other.respond_to?(:permitted?)
    permitted? == other.permitted? && parameters == other.parameters
  else
    @parameters == other
  end
end

def [](key)

Experimental RBS support (using type sampling data from the type_fusion project).

def []: ((Symbol | String) key) -> String?

This signature was generated using 12 samples from 2 applications.

params[:none] # => nil
params[:person] # => #"Francesco"} permitted: false>
params = ActionController::Parameters.new(person: { name: "Francesco" })

returns +nil+.
Returns a parameter for the given +key+. If not found,
def [](key)
  convert_hashes_to_parameters(key, @parameters[key])
end

def []=(key, value)

Experimental RBS support (using type sampling data from the type_fusion project).

def []=: (String key, String value) -> String

This signature was generated using 2 samples from 1 application.

when #permit is called.
Assigns a value to a given +key+. The given key may still get filtered out
def []=(key, value)
  @parameters[key] = value
end

def array_of_permitted_scalars?(value)

def array_of_permitted_scalars?(value)
  if value.is_a?(Array) && value.all? { |element| permitted_scalar?(element) }
    yield value
  end
end

def compact

Returns a new ActionController::Parameters instance with +nil+ values removed.
def compact
  new_instance_with_inherited_permitted_status(@parameters.compact)
end

def compact!

Removes all +nil+ values in place and returns +self+, or +nil+ if no changes were made.
def compact!
  self if @parameters.compact!
end

def compact_blank

Uses Object#blank? for determining if a value is blank.
Returns a new ActionController::Parameters instance without the blank values.
def compact_blank
  reject { |_k, v| v.blank? }
end

def compact_blank!

Uses Object#blank? for determining if a value is blank.
Removes all blank values in place and returns self.
def compact_blank!
  reject! { |_k, v| v.blank? }
end

def convert_hashes_to_parameters(key, value)

Experimental RBS support (using type sampling data from the type_fusion project).

type ActionController__Parameters_convert_hashes_to_parameters_value = String | Array[String] | nil | Hash
type ActionController__Parameters_convert_hashes_to_parameters_value = String |  | nil | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | Array | String | String | String | Array | String | String | String | return_value | String

def convert_hashes_to_parameters: ((String | Symbol) key, ActionController__Parameters_convert_hashes_to_parameters_value value) -> (String | nil | ActionController::Parameters)

This signature was generated using 24 samples from 2 applications.

def convert_hashes_to_parameters(key, value)
  converted = convert_value_to_parameters(value)
  @parameters[key] = converted unless converted.equal?(value)
  converted
end

def convert_parameters_to_hashes(value, using)

Experimental RBS support (using type sampling data from the type_fusion project).

def convert_parameters_to_hashes: (String value, Symbol using) -> String

This signature was generated using 2 samples from 1 application.

def convert_parameters_to_hashes(value, using)
  case value
  when Array
    value.map { |v| convert_parameters_to_hashes(v, using) }
  when Hash
    value.transform_values do |v|
      convert_parameters_to_hashes(v, using)
    end.with_indifferent_access
  when Parameters
    value.send(using)
  else
    value
  end
end

def convert_value_to_parameters(value)

Experimental RBS support (using type sampling data from the type_fusion project).

def convert_value_to_parameters: (String? value) -> String?

This signature was generated using 14 samples from 1 application.

def convert_value_to_parameters(value)
  case value
  when Array
    return value if converted_arrays.member?(value)
    converted = value.map { |_| convert_value_to_parameters(_) }
    converted_arrays << converted.dup
    converted
  when Hash
    self.class.new(value, @logging_context)
  else
    value
  end
end

def converted_arrays

object per fetch.
loop that converts values. Also, we are not going to build a new array
\Testing membership still loops, but it's going to be faster than our own

method to instantiate it only if needed.
looping in the common use case permit + mass-assignment. Defined in a
Attribute that keeps track of converted arrays, if any, to avoid double
def converted_arrays
  @converted_arrays ||= Set.new
end

def deep_dup

Returns a duplicate +ActionController::Parameters+ instance with the same permitted parameters.
def deep_dup
  self.class.new(@parameters.deep_dup, @logging_context).tap do |duplicate|
    duplicate.permitted = @permitted
  end
end

def deep_transform_keys(&block)

from the root hash and from all nested hashes and arrays. The values are unchanged.
results of running +block+ once for every key. This includes the keys
Returns a new ActionController::Parameters instance with the
def deep_transform_keys(&block)
  new_instance_with_inherited_permitted_status(
    @parameters.deep_transform_keys(&block)
  )
end

def deep_transform_keys!(&block)

nested hashes and arrays. The values are unchanged.
changed keys. This includes the keys from the root hash and from all
Returns the same ActionController::Parameters instance with
def deep_transform_keys!(&block)
  @parameters.deep_transform_keys!(&block)
  self
end

def delete(key, &block)

returns the corresponding +ActionController::Parameters+ object.
+key+ and returns the result). This method is similar to #extract!, which
+key+ is not found, returns +nil+ (or, with optional code block, yields
Deletes a key-value pair from +Parameters+ and returns the value. If
def delete(key, &block)
  convert_value_to_parameters(@parameters.delete(key, &block))
end

def dig(*keys)

params2.dig(:foo, 1) # => 11
params2 = ActionController::Parameters.new(foo: [10, 11, 12])

params.dig(:foo, :zot, :xyz) # => nil
params.dig(:foo, :bar, :baz) # => 1
params = ActionController::Parameters.new(foo: { bar: { baz: 1 } })

at each step. Returns +nil+ if any intermediate step is +nil+.
Extracts the nested parameter from the given +keys+ by calling +dig+
def dig(*keys)
  convert_hashes_to_parameters(keys.first, @parameters[keys.first])
  @parameters.dig(*keys)
end

def each_element(object, filter, &block)

def each_element(object, filter, &block)
  case object
  when Array
    object.grep(Parameters).filter_map(&block)
  when Parameters
    if object.nested_attributes? && !specify_numeric_keys?(filter)
      object.each_nested_attribute(&block)
    else
      yield object
    end
  end
end

def each_nested_attribute

def each_nested_attribute
  hash = self.class.new
  self.each { |k, v| hash[k] = yield v if Parameters.nested_attribute?(k, v) }
  hash
end

def each_pair(&block)

the same way as Hash#each_pair.
Convert all hashes in values into parameters, then yield each pair in
def each_pair(&block)
  return to_enum(__callee__) unless block_given?
  @parameters.each_pair do |key, value|
    yield [key, convert_hashes_to_parameters(key, value)]
  end
  self
end

def each_value(&block)

the same way as Hash#each_value.
Convert all hashes in values into parameters, then yield each value in
def each_value(&block)
  return to_enum(:each_value) unless block_given?
  @parameters.each_pair do |key, value|
    yield convert_hashes_to_parameters(key, value)
  end
  self
end

def encode_with(coder) # :nodoc:

:nodoc:
def encode_with(coder) # :nodoc:
  coder.map = { "parameters" => @parameters, "permitted" => @permitted }
end

def eql?(other)

def eql?(other)
  self.class == other.class &&
    permitted? == other.permitted? &&
    parameters.eql?(other.parameters)
end

def except(*keys)

params.except(:d) # => #1, "b"=>2, "c"=>3} permitted: false>
params.except(:a, :b) # => #3} permitted: false>
params = ActionController::Parameters.new(a: 1, b: 2, c: 3)

filters out the given +keys+.
Returns a new ActionController::Parameters instance that
def except(*keys)
  new_instance_with_inherited_permitted_status(@parameters.except(*keys))
end

def extract!(*keys)

params # => #3} permitted: false>
params.extract!(:a, :b) # => #1, "b"=>2} permitted: false>
params = ActionController::Parameters.new(a: 1, b: 2, c: 3)

Removes and returns the key/value pairs matching the given keys.
def extract!(*keys)
  new_instance_with_inherited_permitted_status(@parameters.extract!(*keys))
end

def fetch(key, *args)

params.fetch(:none) { "Francesco" } # => "Francesco"
params.fetch(:none, "Francesco") # => "Francesco"
params.fetch(:none, {}) # => #
params.fetch(:none) # => ActionController::ParameterMissing: param is missing or the value is empty: none
params.fetch(:person) # => #"Francesco"} permitted: false>
params = ActionController::Parameters.new(person: { name: "Francesco" })

is given, then that will be run and its result returned.
instance of +ActionController::Parameters+ if possible); if a block
if a second argument is given, then that is returned (converted to an
it will raise an ActionController::ParameterMissing error;
can't be found, there are several options: With no other arguments,
Returns a parameter for the given +key+. If the +key+
def fetch(key, *args)
  convert_value_to_parameters(
    @parameters.fetch(key) {
      if block_given?
        yield
      else
        args.fetch(0) { raise ActionController::ParameterMissing.new(key, @parameters.keys) }
      end
    }
  )
end

def hash

def hash
  [self.class, @parameters, @permitted].hash
end

def hash_filter(params, filter)

:nodoc:
:nodoc:
def hash_filter(params, filter)
  filter = filter.with_indifferent_access
  # Slicing filters out non-declared keys.
  slice(*filter.keys).each do |key, value|
    next unless value
    next unless has_key? key
    if filter[key] == EMPTY_ARRAY
      # Declaration { comment_ids: [] }.
      array_of_permitted_scalars?(self[key]) do |val|
        params[key] = val
      end
    elsif filter[key] == EMPTY_HASH
      # Declaration { preferences: {} }.
      if value.is_a?(Parameters)
        params[key] = permit_any_in_parameters(value)
      end
    elsif non_scalar?(value)
      # Declaration { user: :name } or { user: [:name, :age, { address: ... }] }.
      params[key] = each_element(value, filter[key]) do |element|
        element.permit(*Array.wrap(filter[key]))
      end
    end
  end
end

def init_with(coder) # :nodoc:

:nodoc:
def init_with(coder) # :nodoc:
  case coder.tag
  when "!ruby/hash:ActionController::Parameters"
    # YAML 2.0.8's format where hash instance variables weren't stored.
    @parameters = coder.map.with_indifferent_access
    @permitted  = false
  when "!ruby/hash-with-ivars:ActionController::Parameters"
    # YAML 2.0.9's Hash subclass format where keys and values
    # were stored under an elements hash and `permitted` within an ivars hash.
    @parameters = coder.map["elements"].with_indifferent_access
    @permitted  = coder.map["ivars"][:@permitted]
  when "!ruby/object:ActionController::Parameters"
    # YAML's Object format. Only needed because of the format
    # backwards compatibility above, otherwise equivalent to YAML's initialization.
    @parameters, @permitted = coder.map["parameters"], coder.map["permitted"]
  end
end

def initialize(parameters = {}, logging_context = {})

Experimental RBS support (using type sampling data from the type_fusion project).

def initialize: (? parameters, ? logging_context) -> void

This signature was generated using 1 sample from 1 application.

Person.new(params) # => #
params.permitted? # => true
params = ActionController::Parameters.new(name: "Francesco")

ActionController::Parameters.permit_all_parameters = true

Person.new(params) # => ActiveModel::ForbiddenAttributesError
params.permitted? # => false
params = ActionController::Parameters.new(name: "Francesco")

end
class Person < ActiveRecord::Base

ActionController::Parameters.permit_all_parameters.
Also, sets the +permitted+ attribute to the default value of
Returns a new ActionController::Parameters instance.
def initialize(parameters = {}, logging_context = {})
  @parameters = parameters.with_indifferent_access
  @logging_context = logging_context
  @permitted = self.class.permit_all_parameters
end

def initialize_copy(source)

def initialize_copy(source)
  super
  @parameters = @parameters.dup
end

def inspect

def inspect
  "#<#{self.class} #{@parameters} permitted: #{@permitted}>"
end

def merge(other_hash)

+other_hash+ merged into current hash.
Returns a new ActionController::Parameters instance with all keys from
def merge(other_hash)
  new_instance_with_inherited_permitted_status(
    @parameters.merge(other_hash.to_h)
  )
end

def merge!(other_hash)

+other_hash+ merged into current hash.
Returns the current ActionController::Parameters instance with
def merge!(other_hash)
  @parameters.merge!(other_hash.to_h)
  self
end

def nested_attribute?(key, value) # :nodoc:

:nodoc:
def nested_attribute?(key, value) # :nodoc:
  /\A-?\d+\z/.match?(key) && (value.is_a?(Hash) || value.is_a?(Parameters))
end

def nested_attributes?

def nested_attributes?
  @parameters.any? { |k, v| Parameters.nested_attribute?(k, v) }
end

def new_instance_with_inherited_permitted_status(hash)

Experimental RBS support (using type sampling data from the type_fusion project).

def new_instance_with_inherited_permitted_status: ( hash) -> ActionController::Parameters

This signature was generated using 1 sample from 1 application.

def new_instance_with_inherited_permitted_status(hash)
  self.class.new(hash, @logging_context).tap do |new_instance|
    new_instance.permitted = @permitted
  end
end

def non_scalar?(value)

def non_scalar?(value)
  value.is_a?(Array) || value.is_a?(Parameters)
end

def permit(*filters)

# => {"person"=>{"0"=>{"email"=>"none@test.com"}, "1"=>{"phone"=>"555-6789"}}}
params.permit(person: { '0': [:email], '1': [:phone]}).to_h
})
}
},
phone: "555-6789"
email: "nothing@test.com",
'1': {
},
phone: "555-1234"
email: "none@test.com",
'0': {
person: {
params = ActionController::Parameters.new({

If you want to specify what keys you want from each numeric key, you can instead specify each one individually

# => {"person"=>{"0"=>{"email"=>"none@test.com"}, "1"=>{"email"=>"nothing@test.com"}}}
params.permit(person: [:email]).to_h
})
}
},
phone: "555-6789"
email: "nothing@test.com",
'1': {
},
phone: "555-1234"
email: "none@test.com",
'0': {
person: {
params = ActionController::Parameters.new({

you can permit each set of parameters under the numeric key to be the same using the same syntax as permitting a single item.
If your parameters specify multiple parameters indexed by a number,

# => ##"none@test.com", "phone"=>"555-1234"} permitted: true>} permitted: true>
params.require(:person).permit(contact: [ :email, :phone ])

# => ##"555-1234"} permitted: true>} permitted: true>
params.require(:person).permit(contact: :phone)

# => #
params.require(:person).permit(:contact)

})
}
}
phone: "555-1234"
email: "none@test.com",
contact: {
person: {
params = ActionController::Parameters.new({

attributes inside the hash should be permitted.
it won't allow all the hash. You also need to specify which
Note that if you use +permit+ in a key that points to a hash,

permitted[:person][:pets][0][:category] # => nil
permitted[:person][:pets][0][:name] # => "Purplish"
permitted[:person][:age] # => nil
permitted[:person][:name] # => "Francesco"
permitted.permitted? # => true
permitted = params.permit(person: [ :name, { pets: :name } ])

})
}
}]
category: "dogs"
name: "Purplish",
pets: [{
age: 22,
name: "Francesco",
person: {
params = ActionController::Parameters.new({

You can also use +permit+ on nested parameters, like:

scalars and filters out anything else.
case, +permit+ ensures values in the returned structure are permitted
Be careful because this opens the door to arbitrary input. In this

params.permit(preferences: {})

a hash parameter or its internal structure. Just map to an empty hash:
Sometimes it is not possible or convenient to declare the valid keys of

params.permit(tags: [])
params = ActionController::Parameters.new(tags: ["rails", "parameters"])

by mapping it to an empty array:
You may declare that the parameter should be an array of permitted scalars

Otherwise, the key +:name+ is filtered out.
ActionDispatch::Http::UploadedFile or +Rack::Test::UploadedFile+.
+Date+, +Time+, +DateTime+, +StringIO+, +IO+,
+String+, +Symbol+, +NilClass+, +Numeric+, +TrueClass+, +FalseClass+,
+:name+ passes if it is a key of +params+ whose associated value is of type

params.permit(:name)

Only permitted scalars pass the filter. For example, given

permitted.has_key?(:role) # => false
permitted.has_key?(:age) # => true
permitted.has_key?(:name) # => true
permitted.permitted? # => true
permitted = params.require(:user).permit(:name, :age)
params = ActionController::Parameters.new(user: { name: "Francesco", age: 22, role: "admin" })

should be allowed for mass updating.
for the object to +true+. This is useful for limiting which attributes
includes only the given +filters+ and sets the +permitted+ attribute
Returns a new ActionController::Parameters instance that
def permit(*filters)
  params = self.class.new
  filters.flatten.each do |filter|
    case filter
    when Symbol, String
      permitted_scalar_filter(params, filter)
    when Hash
      hash_filter(params, filter)
    end
  end
  unpermitted_parameters!(params) if self.class.action_on_unpermitted_parameters
  params.permit!
end

def permit!

Person.new(params) # => #
params.permitted? # => true
params.permit!
Person.new(params) # => ActiveModel::ForbiddenAttributesError
params.permitted? # => false
params = ActionController::Parameters.new(name: "Francesco")

end
class Person < ActiveRecord::Base

mass assignment. Returns +self+.
Sets the +permitted+ attribute to +true+. This can be used to pass
def permit!
  each_pair do |key, value|
    Array.wrap(value).flatten.each do |v|
      v.permit! if v.respond_to? :permit!
    end
  end
  @permitted = true
  self
end

def permit_any_in_array(array)

def permit_any_in_array(array)
  [].tap do |sanitized|
    array.each do |element|
      case element
      when ->(e) { permitted_scalar?(e) }
        sanitized << element
      when Parameters
        sanitized << permit_any_in_parameters(element)
      else
        # Filter this one out.
      end
    end
  end
end

def permit_any_in_parameters(params)

def permit_any_in_parameters(params)
  self.class.new.tap do |sanitized|
    params.each do |key, value|
      case value
      when ->(v) { permitted_scalar?(v) }
        sanitized[key] = value
      when Array
        sanitized[key] = permit_any_in_array(value)
      when Parameters
        sanitized[key] = permit_any_in_parameters(value)
      else
        # Filter this one out.
      end
    end
  end
end

def permitted?

params.permitted? # => true
params.permit!
params.permitted? # => false
params = ActionController::Parameters.new

Returns +true+ if the parameter is permitted, +false+ otherwise.
def permitted?
  @permitted
end

def permitted_scalar?(value)

Experimental RBS support (using type sampling data from the type_fusion project).

def permitted_scalar?: (String value) -> true

This signature was generated using 1 sample from 1 application.

def permitted_scalar?(value)
  PERMITTED_SCALAR_TYPES.any? { |type| value.is_a?(type) }
end

def permitted_scalar_filter(params, permitted_key)

Experimental RBS support (using type sampling data from the type_fusion project).

def permitted_scalar_filter: (ActionController::Parameters params, String permitted_key) -> untyped

This signature was generated using 4 samples from 2 applications.

puts params.keys # => ["zipcode"]

permitted_scalar_filter(params, "zipcode")

params = {}
puts self.keys #=> ["zipcode(90210i)"]

For example:

Adds existing keys to the params if their values are scalar.
def permitted_scalar_filter(params, permitted_key)
  permitted_key = permitted_key.to_s
  if has_key?(permitted_key) && permitted_scalar?(self[permitted_key])
    params[permitted_key] = self[permitted_key]
  end
  each_key do |key|
    next unless key =~ /\(\d+[if]?\)\z/
    next unless $~.pre_match == permitted_key
    params[key] = self[key] if permitted_scalar?(self[key])
  end
end

def reject(&block)

that the block evaluates to true removed.
Returns a new ActionController::Parameters instance with items
def reject(&block)
  new_instance_with_inherited_permitted_status(@parameters.reject(&block))
end

def reject!(&block)

Removes items that the block evaluates to true and returns self.
def reject!(&block)
  @parameters.reject!(&block)
  self
end

def require(key)

for example.

end
end
person_params.require(:name) # SAFER
params.require(:person).permit(:name).tap do |person_params|
def person_params

but take into account that at some point those ones have to be permitted:

name = params.require(:person).require(:name) # CAREFUL
params = ActionController::Parameters.new(person: { name: "Finn" })
# CAREFUL

Technically this method can be used to fetch terminal values:

# ActionController::ParameterMissing: param is missing or the value is empty: user
user_params, profile_params = params.require([:user, :profile])
params = ActionController::Parameters.new(user: {}, profile: {})

Otherwise, the method re-raises the first exception found:

user_params, profile_params = params.require([:user, :profile])
params = ActionController::Parameters.new(user: { ... }, profile: { ... })

returned:
in order. If it succeeds, an array with the respective return values is
When given an array of keys, the method tries to require each one of them

# ActionController::ParameterMissing: param is missing or the value is empty: person
ActionController::Parameters.new(person: {}).require(:person)

# ActionController::ParameterMissing: param is missing or the value is empty: person
ActionController::Parameters.new(person: "\t").require(:person)

# ActionController::ParameterMissing: param is missing or the value is empty: person
ActionController::Parameters.new(person: nil).require(:person)

# ActionController::ParameterMissing: param is missing or the value is empty: person
ActionController::Parameters.new.require(:person)

Otherwise raises ActionController::ParameterMissing:

# => #"Francesco"} permitted: false>
ActionController::Parameters.new(person: { name: "Francesco" }).require(:person)

either present or the singleton +false+, returns said value:
When passed a single key, if it exists and its associated value is

This method accepts both a single key and an array of keys.
def require(key)
  return key.map { |k| require(k) } if key.is_a?(Array)
  value = self[key]
  if value.present? || value == false
    value
  else
    raise ParameterMissing.new(key, @parameters.keys)
  end
end

def reverse_merge(other_hash)

from current hash merged into +other_hash+.
Returns a new ActionController::Parameters instance with all keys
def reverse_merge(other_hash)
  new_instance_with_inherited_permitted_status(
    other_hash.to_h.merge(@parameters)
  )
end

def reverse_merge!(other_hash)

current hash merged into +other_hash+.
Returns the current ActionController::Parameters instance with
def reverse_merge!(other_hash)
  @parameters.merge!(other_hash.to_h) { |key, left, right| left }
  self
end

def select(&block)

items that the block evaluates to true.
Returns a new ActionController::Parameters instance with only
def select(&block)
  new_instance_with_inherited_permitted_status(@parameters.select(&block))
end

def select!(&block)

Equivalent to Hash#keep_if, but returns +nil+ if no changes were made.
def select!(&block)
  @parameters.select!(&block)
  self
end

def slice(*keys)

Experimental RBS support (using type sampling data from the type_fusion project).

def slice: (* keys) -> ActionController::Parameters

This signature was generated using 1 sample from 1 application.

params.slice(:d) # => #
params.slice(:a, :b) # => #1, "b"=>2} permitted: false>
params = ActionController::Parameters.new(a: 1, b: 2, c: 3)

don't exist, returns an empty hash.
includes only the given +keys+. If the given +keys+
Returns a new ActionController::Parameters instance that
def slice(*keys)
  new_instance_with_inherited_permitted_status(@parameters.slice(*keys))
end

def slice!(*keys)

contains only the given +keys+.
Returns the current ActionController::Parameters instance which
def slice!(*keys)
  @parameters.slice!(*keys)
  self
end

def specify_numeric_keys?(filter)

def specify_numeric_keys?(filter)
  if filter.respond_to?(:keys)
    filter.keys.any? { |key| /\A-?\d+\z/.match?(key) }
  end
end

def stringify_keys # :nodoc:

:nodoc:
matter as we are using +HashWithIndifferentAccess+ internally.
pass +Parameters+ to a mass assignment methods in a model. It should not
This is required by ActiveModel attribute assignment, so that user can
def stringify_keys # :nodoc:
  dup
end

def to_h

safe_params.to_h # => {"name"=>"Senjougahara Hitagi"}
safe_params = params.permit(:name)

# => ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash
params.to_h
})
oddity: "Heavy stone crab"
name: "Senjougahara Hitagi",
params = ActionController::Parameters.new({

representation of the parameters with all unpermitted keys removed.
Returns a safe ActiveSupport::HashWithIndifferentAccess
def to_h
  if permitted?
    convert_parameters_to_hashes(@parameters, :to_h)
  else
    raise UnfilteredParameters
  end
end

def to_hash

safe_params.to_hash # => {"name"=>"Senjougahara Hitagi"}
safe_params = params.permit(:name)

# => ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash
params.to_hash
})
oddity: "Heavy stone crab"
name: "Senjougahara Hitagi",
params = ActionController::Parameters.new({

with all unpermitted keys removed.
Returns a safe Hash representation of the parameters
def to_hash
  to_h.to_hash
end

def to_query(*args)

are sorted lexicographically in ascending order.
The string pairs "key=value" that conform the query string

# => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
safe_params.to_query("user")
safe_params = params.permit(:name, :nationality)
})
nationality: "Danish"
name: "David",
params = ActionController::Parameters.new({

An optional namespace can be passed to enclose key names:

# => "name=David&nationality=Danish"
safe_params.to_query
safe_params = params.permit(:name, :nationality)

# => ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash
params.to_query
})
nationality: "Danish"
name: "David",
params = ActionController::Parameters.new({

query string:
Returns a string representation of the receiver suitable for use as a URL
def to_query(*args)
  to_h.to_query(*args)
end

def to_unsafe_h

# => {"name"=>"Senjougahara Hitagi", "oddity" => "Heavy stone crab"}
params.to_unsafe_h
})
oddity: "Heavy stone crab"
name: "Senjougahara Hitagi",
params = ActionController::Parameters.new({

representation of the parameters.
Returns an unsafe, unfiltered ActiveSupport::HashWithIndifferentAccess
def to_unsafe_h
  convert_parameters_to_hashes(@parameters, :to_unsafe_h)
end

def transform_keys(&block)

results of running +block+ once for every key. The values are unchanged.
Returns a new ActionController::Parameters instance with the
def transform_keys(&block)
  return to_enum(:transform_keys) unless block_given?
  new_instance_with_inherited_permitted_status(
    @parameters.transform_keys(&block)
  )
end

def transform_keys!(&block)

ActionController::Parameters instance.
Performs keys transformation and returns the altered
def transform_keys!(&block)
  return to_enum(:transform_keys!) unless block_given?
  @parameters.transform_keys!(&block)
  self
end

def transform_values

# => #2, "b"=>4, "c"=>6} permitted: false>
params.transform_values { |x| x * 2 }
params = ActionController::Parameters.new(a: 1, b: 2, c: 3)

running +block+ once for every value. The keys are unchanged.
Returns a new ActionController::Parameters instance with the results of
def transform_values
  return to_enum(:transform_values) unless block_given?
  new_instance_with_inherited_permitted_status(
    @parameters.transform_values { |v| yield convert_value_to_parameters(v) }
  )
end

def transform_values!

ActionController::Parameters instance.
Performs values transformation and returns the altered
def transform_values!
  return to_enum(:transform_values!) unless block_given?
  @parameters.transform_values! { |v| yield convert_value_to_parameters(v) }
  self
end

def unpermitted_keys(params)

def unpermitted_keys(params)
  keys - params.keys - always_permitted_parameters
end

def unpermitted_parameters!(params)

Experimental RBS support (using type sampling data from the type_fusion project).

def unpermitted_parameters!: (ActionController::Parameters params) -> nil

This signature was generated using 1 sample from 1 application.

def unpermitted_parameters!(params)
  unpermitted_keys = unpermitted_keys(params)
  if unpermitted_keys.any?
    case self.class.action_on_unpermitted_parameters
    when :log
      name = "unpermitted_parameters.action_controller"
      ActiveSupport::Notifications.instrument(name, keys: unpermitted_keys, context: @logging_context)
    when :raise
      raise ActionController::UnpermittedParameters.new(unpermitted_keys)
    end
  end
end

def values_at(*keys)

+Hash+ objects will be converted to ActionController::Parameters.
Returns values that were assigned to the given +keys+. Note that all the
def values_at(*keys)
  convert_value_to_parameters(@parameters.values_at(*keys))
end