Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

rails model on validation custom column name

# 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"
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #rails #model #validation #custom #column
ADD COMMENT
Topic
Name
1+4 =