converted_arrays

converted_arrays() Instance Public methods Attribute that keeps track of converted arrays, if any, to avoid double looping in the common use case permit + mass-assignment. Defined in a method to instantiate it only if needed.

dup

dup() Instance Public methods Returns an exact copy of the ActionController::Parameters instance. permitted state is kept on the duped object. params = ActionController::Parameters.new(a: 1) params.permit! params.permitted? # => true copy_params = params.dup # => {"a"=>1} copy_params.permitted? # => true

fetch

fetch(key, *args) Instance Public methods Returns a parameter for the given key. If the key can't be found, there are several options: With no other arguments, it will raise an ActionController::ParameterMissing error; if more arguments are given, then that will be returned; if a block is given, then that will be run and its result returned. params = ActionController::Parameters.new(person: { name: 'Francesco' }) params.fetch(:person) # => {"name"=>"Francesco"}

permit

permit(*filters) Instance Public methods Returns a new ActionController::Parameters instance that includes only the given filters and sets the permitted attribute for the object to true. This is useful for limiting which attributes should be allowed for mass updating. params = ActionController::Parameters.new(user: { name: 'Francesco', age: 22, role: 'admin' }) permitted = params.require(:user).permit(:name, :age) permitted.permitted? # => true permitted.has_key?(:name) # =

permit!

permit!() Instance Public methods Sets the permitted attribute to true. This can be used to pass mass assignment. Returns self. class Person < ActiveRecord::Base end params = ActionController::Parameters.new(name: 'Francesco') params.permitted? # => false Person.new(params) # => ActiveModel::ForbiddenAttributesError params.permit! params.permitted? # => true Person.new(params) # => #<Person id: nil, name: "Francesco">

permitted?

permitted?() Instance Public methods Returns true if the parameter is permitted, false otherwise. params = ActionController::Parameters.new params.permitted? # => false params.permit! params.permitted? # => true

require

require(key) Instance Public methods Ensures that a parameter is present. If it's present, returns the parameter at the given key, otherwise raises an ActionController::ParameterMissing error. ActionController::Parameters.new(person: { name: 'Francesco' }).require(:person) # => {"name"=>"Francesco"} ActionController::Parameters.new(person: nil).require(:person) # => ActionController::ParameterMissing: param not found: person ActionController::Parameters.new(person: {}).r

required

required(key) Instance Public methods Alias of require. require

slice

slice(*keys) Instance Public methods Returns a new ActionController::Parameters instance that includes only the given keys. If the given keys don't exist, returns an empty hash. params = ActionController::Parameters.new(a: 1, b: 2, c: 3) params.slice(:a, :b) # => {"a"=>1, "b"=>2} params.slice(:d) # => {}

permitted=

permitted=(new_permitted) Instance Protected methods