Modèle de rails sur la validation Nom de la colonne personnalisée
# 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"
Fragile Flatworm