instance method
dig
Ruby on Rails 6.0.6
Since v5.2.8.1Signature
dig(*keys)
Extracts the nested parameter from the given keys by calling dig at each step. Returns nil if any intermediate step is nil.
params = ActionController::Parameters.new(foo: { bar: { baz: 1 } }) params.dig(:foo, :bar, :baz) # => 1 params.dig(:foo, :zot, :xyz) # => nil params2 = ActionController::Parameters.new(foo: [10, 11, 12]) params2.dig(:foo, 1) # => 11
Parameters
-
keysrest
Source
# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 614
def dig(*keys)
convert_hashes_to_parameters(keys.first, @parameters[keys.first])
@parameters.dig(*keys)
end
Defined in actionpack/lib/action_controller/metal/strong_parameters.rb line 614
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionController::Parameters