Class: AtLeastOneOfValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- AtLeastOneOfValidator
- Defined in:
- lib/at_least_one_of_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/at_least_one_of_validator.rb', line 6 def validate_each(record, attribute, value) attributes = [:in] + [attribute] if attributes.all? { |name| record.try(name).nil? } record.errors.add(attribute, "is required because at least one of #{attributes.to_sentence} are required") end end |