Class: PostcodeFormatValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/postoffice.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(object, attribute, value) ⇒ Object



181
182
183
184
185
186
187
188
# File 'lib/postoffice.rb', line 181

def validate_each(object, attribute, value)
  
  result = PostOffice.validate_postcode(value, options[:country_code])

  if !result
    object.errors[attribute] << (options[:message] || "entered is not a valid postcode for #{PostOffice.country_name(options[:country_code])}.") 
  end
end