Class: SimplyCouch::Model::Validations::UniquenessValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/simply_couch/model/validations.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
11
# File 'lib/simply_couch/model/validations.rb', line 6

def validate_each(record, attribute, value)
  other_instance = record.class.send("find_by_#{attribute}", value)
  if other_instance && other_instance != record && other_instance.send(attribute) == value
    record.errors.add(attribute, :taken, **options.except(:case_sensitive, :scope).merge(:value => value))
  end
end