Rails ActiveRecord - get all checks from the model

Is there a way to find all the specific checks for the model. For instance:

class Temp < ActiveRecord::Base validate_uniqueness_of :name validate :some_method def some_method ... end end 

When I try:

 Temp.validators 

He finds only a test of uniqueness, but not another.

+5
source share
1 answer

I solved this using:

 Model._validate_callbacks.to_a.reject { |validation| validation.filter.to_s.starts_with?('validate_associated_records') } 

"reject" is used to ignore some default checks.

+2
source

Source: https://habr.com/ru/post/1215864/


All Articles