Class: ValidatesBelongsTo::BelongsToValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validates_belongs_to.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, owner) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/validates_belongs_to.rb', line 18

def validate_each(record, attribute, owner)
  association       = record.class.reflect_on_association(attribute)
  association_type  = association.macro
  method            = "validate_by_#{association_type}"

  send(method, record, attribute, owner) if respond_to?(method)
end