Validtions in Rails Model

Different Validations in Rails :

  1. validates_presence_of  :status
  2. validates_numericality_of :fingers
  3. validates_uniqueness_of :toothmarks
  4. validates_confirmation_of :password
  5. validates_acceptance_of :zombification
  6. validates_length_of :password, minimum: 3
  7. validates_format_of :email, with: /regex/i
  8. validates_inclusion_of :age, in: 21..99
  9. validates_exclusion_of :age, in: 0…21,
  10. message: “Sorry you must be over 21”

Including multiple validations in one line ( ‘ ,’  separated)

validates :status,   presence: true,
uniqueness: true,
numericality: true,
length: { minimum: 0, maximum: 2000 },
format: { with: /.*/ },
acceptance: true,
confirmation: true


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

Up ↑

%d bloggers like this: