Class: ActiveModel::Validations::AssociatedValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/evelpidon_validators/associated.rb

Overview

Shamelessly stolen from: github.com/rails/rails/blob/v3.1.1/activerecord/lib/active_record/validations/associated.rb

Beware! This validator is not triggered in the client side, however if the association is in a form, client side validations will handle that on its own.

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



9
10
11
12
# File 'lib/evelpidon_validators/associated.rb', line 9

def validate_each(record, attribute, value)
  return if (value.is_a?(Array) ? value : [value]).collect{ |r| r.nil? || r.valid? }.all?
  record.errors.add(attribute, :invalid, options.merge(:value => value))
end