Module: NestedValidation

Included in:
QcReception, QcResultsUpload, Reception, Reception::ResourceFactory
Defined in:
app/models/concerns/nested_validation.rb

Overview

Module NestedValidation provides an ActiveModel compatible version of validates associated. Unlike the active model version however it actually propagates the error outwards.

Set the optional, flatten_keys argument to false to maintain the association name in the error. Eg. errors.add(‘association.attribute’, ‘message’)

Usage:

class MyHappyClass extend NestedValidation

validates_nested :my_other_active_model_object, flatten_keys: false

end

Defined Under Namespace

Classes: NestedValidator

Instance Method Summary collapse

Instance Method Details

#validates_nested(*attr_names) ⇒ NestedValidator

Records of this class will call valid? on any associations provided as attr_names. Errors on these records will be propagated out

Parameters:

  • attr_names (Symbol)

    One or more associations to validate

Returns:



68
69
70
# File 'app/models/concerns/nested_validation.rb', line 68

def validates_nested(*attr_names)
  validates_with NestedValidator, _merge_attributes(attr_names)
end