instance method
fetch
Ruby on Rails 4.0.13
Since v4.0.13Signature
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
-
keyreq -
argsrest
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