Class: Attributable::CustomValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/models/attributable/custom_validator.rb

Overview

A custom validator allows options to be imported from the database.

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



5
6
7
8
9
# File 'app/models/attributable/custom_validator.rb', line 5

def validate_each(record, attribute, value)
  valid = record.validator_for(attribute).validate?(value)
  record.errors.add(attribute, 'is not a valid option') unless valid
  valid
end