Module: DataMapper::Validations::ValidatesConfirmation

Extended by:
Deprecate
Included in:
ClassMethods
Defined in:
lib/dm-validations/validators/confirmation_validator.rb

Overview

class ConfirmationValidator

Instance Method Summary collapse

Instance Method Details

#validates_confirmation_of(*fields) ⇒ Object

Validates that the given attribute is confirmed by another attribute. A common use case scenario is when you require a user to confirm their password, for which you use both password and password_confirmation attributes.

Examples:

Usage

require 'dm-validations'

class Page
  include DataMapper::Resource

  property :password, String
  property :email, String
  attr_accessor :password_confirmation
  attr_accessor :email_repeated

  validates_confirmation_of :password
  validates_confirmation_of :email, :confirm => :email_repeated

  # a call to valid? will return false unless:
  # password == password_confirmation
  # and
  # email == email_repeated

Parameters:

  • [Boolean] (Hash)

    a customizable set of options

  • [Symbol] (Hash)

    a customizable set of options



84
85
86
# File 'lib/dm-validations/validators/confirmation_validator.rb', line 84

def validates_confirmation_of(*fields)
  validators.add(ConfirmationValidator, *fields)
end