Search
 
SCRIPT & CODE EXAMPLE
 

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"
Comment

PREVIOUS NEXT
Code Example
Ruby :: ruby 3 one line method 
Ruby :: render to string rails 
Ruby :: how to access function defined in model rails 
Ruby :: rails check test database 
Ruby :: Replacing consecutive numbers with dash between first and last in a range 
Ruby :: rails multiple rescue 
Ruby :: rails admin overwrite view 
Ruby :: self join relationship rails 
Ruby :: expect method call inside rescue rspec 
Ruby :: how to group array in ruby 
Ruby :: change elements in ruby hashes 
Ruby :: Missing template clients/show with {:locale=[:en], :formats=[:pdf], 
Ruby :: compiler version at runtime 
Ruby :: ruby if statement 
R :: r define nested empty list 
R :: harmonic mean in r 
R :: r list append 
R :: r column to rownames 
R :: how to group by 2 variables in r 
R :: Extract number from string field R 
R :: how to change the index of a dataframe in r 
R :: operators R 
R :: r na if 
R :: count number of columns in r 
R :: extract coefficients from lm in r 
R :: log likelihood in r 
R :: Hello Shiny Server Logic 
R :: r read.csv tab delimited 
R :: faceted bar chart in r 
R :: how the print backslash in r 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =