Both the parent and child have different validators via validate… or validates…
I want to store the result of each validator across all of them
the valid?
command is run on the parent (edited)
when I run valid?
on the parent I can verify with break points all 4 validators 2 on the parent and 2 on child are executed correctly
I am looking to monkey patch the process that loops through each of them
This is an example from AI
def run_validations!(context = nil)
@validator_results = {}
# Gather all validators from this class and its ancestors.
# Note: self.class.validators normally already merges them,
# but using ancestors ensures we capture everything.
all_validators = self.class.ancestors
.select { |ancestor| ancestor.respond_to?(:_validators) }
.map { |ancestor| ancestor.send(:_validators) }
.uniq
all_validators.each do |validator|
# Capture errors before running the validator.
errors_before = errors.dup
# Run the validator on self.
validator.validate(self)
# Determine if the validator added any new errors.
new_errors = errors.to_hash.deep_dup.reject { |attr, messages| errors_before[attr] == messages }
passed = new_errors.empty?
@validator_results[validator.class.name] = {
passed: passed,
new_errors: new_errors
}
end
debugger
errors.empty?
end
The method should return all 4 validators but does not
all_validators = self.class.ancestors
.select { |ancestor| ancestor.respond_to?(:_validators) }
.map { |ancestor| ancestor.send(:_validators) }
.uniq
thoughts?
I know this must be possible, I just can’t see where to patch