instance method normalize_attribute

Ruby on Rails 7.1.6

Since v7.1.6 Last seen in v8.0.4

Available in: v7.1.6 v7.2.3 v8.0.4

Signature

normalize_attribute(name)

Normalizes a specified attribute using its declared normalizations.

Examples

class User < ActiveRecord::Base
  normalizes :email, with: -> email { email.strip.downcase }
end

legacy_user = User.find(1)
legacy_user.email # => " CRUISE-CONTROL@EXAMPLE.COM\n"
legacy_user.normalize_attribute(:email)
legacy_user.email # => "cruise-control@example.com"
legacy_user.save

Parameters

name req
Source
# File activerecord/lib/active_record/normalization.rb, line 26
    def normalize_attribute(name)
      # Treat the value as a new, unnormalized value.
      self[name] = self[name]
    end

Defined in activerecord/lib/active_record/normalization.rb line 26 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Normalization

Type at least 2 characters to search.

↑↓ navigate · open · esc close