instance method fetch

Ruby on Rails 4.1.16

Since v4.0.13

Available in: v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

fetch(key, *args)

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"}
params.fetch(:none)                 # => ActionController::ParameterMissing: param not found: none
params.fetch(:none, 'Francesco')    # => "Francesco"
params.fetch(:none) { 'Francesco' } # => "Francesco"

Parameters

key req
args rest
Source
# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 301
    def fetch(key, *args)
      convert_hashes_to_parameters(key, super, false)
    rescue KeyError
      raise ActionController::ParameterMissing.new(key)
    end

Defined in actionpack/lib/action_controller/metal/strong_parameters.rb line 301 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionController::Parameters

Type at least 2 characters to search.

↑↓ navigate · open · esc close