Module: ActiveRecord::Normalization
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- activerecord/lib/active_record/normalization.rb
Defined Under Namespace
Modules: ClassMethods Classes: NormalizedValueType
Instance Method Summary collapse
-
#normalize_attribute(name) ⇒ Object
Normalizes a specified attribute using its declared normalizations.
Methods included from ActiveSupport::Concern
append_features, class_methods, extended, included, prepend_features, prepended
Instance Method Details
#normalize_attribute(name) ⇒ Object
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 # => " [email protected]\n"
legacy_user.normalize_attribute(:email)
legacy_user.email # => "[email protected]"
legacy_user.save
26 27 28 29 |
# 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 |