Class: PostalCodeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/activemodel-validators/postal_code_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



2
3
4
5
6
7
# File 'lib/activemodel-validators/postal_code_validator.rb', line 2

def validate_each(record, attribute, value)
  return if value.blank?
  if value.to_s.length < 5
    record.errors.add attribute, :postal_code_too_short
  end
end