Module: ActiveModel::Validations::ClassMethods

Defined in:
lib/judopay/model.rb

Instance Method Summary collapse

Instance Method Details

#validate_nested_model(*attr_names) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'lib/judopay/model.rb', line 123

def validate_nested_model(*attr_names)
  validates_with BlockValidator, _merge_attributes(attr_names) do |model, attr, value|
    if value.is_a?(Judopay::Model) && !value.valid?
      value.errors.each { |field, message| model.errors["#{attr}.#{field}"] = message }
    elsif !value.is_a?(Judopay::Model)
      model.errors[attr] = 'should be valid Model object'
    end
  end
end