Module: DataMapper::Validate::ValidatesIsConfirmed

Included in:
ClassMethods
Defined in:
lib/dm-validations/confirmation_validator.rb

Overview

class ConfirmationValidator

Instance Method Summary collapse

Instance Method Details

#validates_is_confirmed(*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_is_confirmed :password
  validates_is_confirmed :email, :confirm => :email_repeated

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

Parameters:

  • :allow_nil<Boolean> (Hash)

    a customizable set of options

  • :confirm<Symbol> (Hash)

    a customizable set of options


73
74
75
76
# File 'lib/dm-validations/confirmation_validator.rb', line 73

def validates_is_confirmed(*fields)
  opts = opts_from_validator_args(fields)
  add_validator_to_context(opts, fields, DataMapper::Validate::ConfirmationValidator)
end