method

normalize_value_for

rails latest stable - Class: ActiveModel::Attributes::Normalization::ClassMethods

Method not available on this version

This method is only available on newer versions. The first available version (v8.1.1) is shown here.

normalize_value_for(name, value)
public

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"