Class: FormModel::AssociatedValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- FormModel::AssociatedValidator
- Defined in:
- lib/form_model/associated_validation.rb
Instance Method Summary collapse
-
#validate_each(form, attribute, value) ⇒ Object
Validates that the associations provided are either all nil or all valid.
Instance Method Details
#validate_each(form, attribute, value) ⇒ Object
Validates that the associations provided are either all nil or all valid. If neither is true then the appropriate errors will be added to the parent document.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/form_model/associated_validation.rb', line 15 def validate_each(form, attribute, value) begin valid = Array.wrap(value).collect do |doc| if doc.nil? true else doc.valid? end end.all? end form.errors.add(attribute, :invalid, ) unless valid end |