Module: CouchRest::Validation::ValidatesIsConfirmed

Included in:
ClassMethods
Defined in:
lib/couchrest/validation/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

class Page < Hash
  include CouchRest::ExtendedModel
  include CouchRest::Validations

  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:

  • :allow_nil<Boolean> (Hash)

    a customizable set of options

  • :confirm<Symbol> (Hash)

    a customizable set of options



92
93
94
95
# File 'lib/couchrest/validation/validators/confirmation_validator.rb', line 92

def validates_confirmation_of(*fields)
  opts = opts_from_validator_args(fields)
  add_validator_to_context(opts, fields, CouchRest::Validation::ConfirmationValidator)
end

#validates_is_confirmed(*fields) ⇒ Object



97
98
99
100
# File 'lib/couchrest/validation/validators/confirmation_validator.rb', line 97

def validates_is_confirmed(*fields)
  warn "[DEPRECATION] `validates_is_confirmed` is deprecated.  Please use `validates_confirmation_of` instead."
  validates_confirmation_of(*fields)
end