instance method dig

Ruby on Rails 6.0.6

Since v5.2.8.1

Available in: 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

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

keys rest
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

Type at least 2 characters to search.

↑↓ navigate · open · esc close