instance method fetch_values

Ruby on Rails edge

Since edge

Signature

fetch_values(*keys)

Returns parameters for the given keys. If a key can’t be found, there are several options: With no other arguments, it will raise an ActionController::ParameterMissing error; if a block is given, then that will be run and its result returned for the missing key.

params = ActionController::Parameters.new(name: "Francesco", age: 22)
params.fetch_values(:name, :age)                # => ["Francesco", 22]
params.fetch_values(:name, :none)               # => ActionController::ParameterMissing: param is missing or the value is empty or invalid: none
params.fetch_values(:name, :none) { |key| key } # => ["Francesco", :none]

Parameters

keys rest
Source
# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 848
    def fetch_values(*keys)
      original_key_lookup = keys.index_by { |key| key.to_s }
      values = @parameters.fetch_values(*keys) do |missing_key|
        original_key = original_key_lookup[missing_key]
        if block_given?
          yield original_key
        else
          raise ActionController::ParameterMissing.new(original_key, @parameters.keys)
        end
      end
      values.map! { |value| convert_value_to_parameters(value) }
    end

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

Defined in ActionController::Parameters

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close