Method: ActionController::Parameters#dig
- Defined in:
- lib/action_controller/metal/strong_parameters.rb
#dig(*keys) ⇒ Object
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
841 842 843 844 |
# File 'lib/action_controller/metal/strong_parameters.rb', line 841 def dig(*keys) convert_hashes_to_parameters(keys.first, @parameters[keys.first]) @parameters.dig(*keys) end |