Ruby on Rails ActiveRecord Validations Confirmation of attribute


Example

You should use this when you have two text fields that should receive exactly the same content. For example, you may want to confirm an email address or a password. This validation creates a virtual attribute whose name is the name of the field that has to be confirmed with _confirmation appended.

class Person < ApplicationRecord
  validates :email, confirmation: true
end

Note This check is performed only if email_confirmation is not nil.

To require confirmation, make sure to add a presence check for the confirmation attribute.

class Person < ApplicationRecord
  validates :email,      confirmation: true
  validates :email_confirmation, presence: true
end

Source