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_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

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

  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



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

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