instance method deep_transform_values

Ruby on Rails edge

Since edge

Signature

deep_transform_values(&block)

Returns a new ActionController::Parameters instance with the results of running block once for every value. This includes the values from the root hash and from all nested hashes and arrays. The keys are unchanged.

The returned instance carries the same permitted status as the receiver, so the result still has to be filtered through permit / expect before being mass-assigned. Prefer this to to_unsafe_h.deep_transform_values, which discards the permitted/unpermitted distinction.

params = ActionController::Parameters.new(
  user: { email: "  ALICE@EXAMPLE.COM  ", profile: { bio: "  Hello world  " } }
)
params.deep_transform_values { |v| v.is_a?(String) ? v.strip.downcase : v }
# => #<ActionController::Parameters {"user"=>{"email"=>"alice@example.com", "profile"=>{"bio"=>"hello world"}}} permitted: false>

Parameters

block block
Source
# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 981
    def deep_transform_values(&block)
      new_instance_with_inherited_permitted_status(
        _deep_transform_values_in_object(@parameters, &block)
      )
    end

Defined in actionpack/lib/action_controller/metal/strong_parameters.rb line 981 · 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