Class: HerExtension::Validations::RemoteUniquenessValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- HerExtension::Validations::RemoteUniquenessValidator
- Defined in:
- lib/her_extension/validations/remote_uniqueness_validation.rb
Overview
Validate the uniqueness of a field by performing a remote API call
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/her_extension/validations/remote_uniqueness_validation.rb', line 9 def validate_each(record,attribute,value) list = record.class.where({ attribute => value }).limit(1) if list.reject { |e| e.id == record.id }.any? = .except(:case_sensitive, :scope, :conditions) [:value] = value record.errors.add(attribute, :taken, ) end end |