跳至内容 跳至搜索
命名空间
方法
N

实例公有方法

normalize_attribute(name)

使用声明的规范化方法对指定属性进行规范化。

示例

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
# 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