当我向 singleton_class 添加验证时,它似乎被分配给了基类,并且它不会触发任何一个。
class Example
attr_accessor :title, :some_boolean
include ActiveModel::Validations
end
puts Example.validators # []
with_validations = Example.new
with_validations.singleton_class.send :validates, :title, :presence => true
puts with_validations.valid? #true
puts Example.validators.length # 1
我想发生的事情:
with_validations.valid? # false
Example.new.valid? # true