Class: SuperModel::Validations::UniquenessValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/supermodel/validations/uniqueness.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



5
6
7
8
9
# File 'lib/supermodel/validations/uniqueness.rb', line 5

def validate_each(record, attribute, value)
  alternate = record.class.find_by_attribute(attribute, value)
  return unless alternate
  record.errors.add(attribute, 'must be unique', default: options[:message])
end