命名空间
方法
实例公有方法
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
来源: 显示 | 在 GitHub 上
# 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