📅  最后修改于: 2022-03-11 15:04:47.050000             🧑  作者: Mango
# model
validates :email, :uniqueness => { message: "is wrong" }
validates :name, :uniqueness => { message: "Your name is wrong" }
HUMANIZED_ATTRIBUTES = {
:email => "E-mail address",
:name => "" # don't include column name in error
}
def self.human_attribute_name(attr, options={})
HUMANIZED_ATTRIBUTES[attr.to_sym] || super
end
# now the errors will be:
"E-mail address is wrong"
"Your name is wrong"
# instead of:
"Email E-mail address is wrong"
"Name Your name is wrong"