Class: Papercat::UniquenessValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/papercat/uniqueness_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



3
4
5
6
# File 'lib/papercat/uniqueness_validator.rb', line 3

def validate(record)
  found = record.class.get(options[:key] => record.public_send(options[:key])).first
  record.errors.add options[:key], :taken if found && found.id != record.id
end