Method: Validatable::Macros#validates_each

Defined in:
lib/validatable/macros.rb

#validates_each(*args) ⇒ Object

call-seq: validates_each(*args)

Validates that the logic evaluates to true

class Address
  include Validatable
  validates_each :zip_code, :logic => lambda { errors.add(:zip_code, "is not valid") if ZipCodeService.allows(zip_code) }
end

The logic option is required.

Configuration options:

* after_validate - A block that executes following the run of a validation
* group - The group that this validation belongs to.  A validation can belong to multiple groups
* if - A block that when executed must return true of the validation will not occur
* level - The level at which the validation should occur
* logic - A block that executes to perform the validation
* message - The message to add to the errors collection when the validation fails
* times - The number of times the validation applies


23
24
25
# File 'lib/validatable/macros.rb', line 23

def validates_each(*args)
  add_validations(args, ValidatesEach)
end