instance method normalize_value_for

Ruby on Rails 8.1.2

Since v8.1.2

Signature

normalize_value_for(name, value)

Normalizes a given value using normalizations declared for name.

Examples

class User
  include ActiveModel::Attributes
  include ActiveModel::Attributes::Normalization

  attribute :email, :string

  normalizes :email, with: -> email { email.strip.downcase }
end

User.normalize_value_for(:email, " CRUISE-CONTROL@EXAMPLE.COM\n")
# => "cruise-control@example.com"

Parameters

name req
value req
Source
# File activemodel/lib/active_model/attributes/normalization.rb, line 134
        def normalize_value_for(name, value)
          type_for_attribute(name).cast(value)
        end

Defined in activemodel/lib/active_model/attributes/normalization.rb line 134 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveModel::Attributes::Normalization::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close