Rails ActiveRecord - 从模型中获取所有验证

Rails ActiveRecord - get all validations from a model

有没有办法找到模型的所有定义验证。例如:

class Temp < ActiveRecord::Base

     validate_uniqueness_of :name
     validate :some_method

     def some_method
        ...
     end
 end

当我尝试时:

Temp.validators

它只找到唯一性验证,而不是另一个。

我已经通过使用解决了它:

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

'reject'用于忽略一些默认验证。