Model Rails on Validasi Nama kolom khusus
# 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