Class: ProductTaxonomy::Indexed::UniquenessValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ProductTaxonomy::Indexed::UniquenessValidator
- Defined in:
- lib/product_taxonomy/models/mixins/indexed.rb
Overview
Validator that checks for uniqueness of a field value across all models in a given index.
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
18 19 20 21 22 |
# File 'lib/product_taxonomy/models/mixins/indexed.rb', line 18 def validate_each(record, attribute, value) if record.class.duplicate?(model: record, field: attribute) record.errors.add(attribute, :taken, message: "\"#{value}\" has already been used") end end |