Mongoid: ActiveModel Numericality Validation, allow_nil does not work
问题 I've defined a Mongoid model with an Integer field for which i validate numericality like this # source.rb class Source field :code, type: Integer validates_numericality_of :code, allow_nil: true The purpose of allow_nil is to validate fields which are present & ignore nil values. But here, allow_nil completely bypasses the numericality check object = Source.new object.code = "ABC" object.valid? => true object => #<Source _id: 50d00b2d81ee9eae46000001, _type: nil, code: 0> In activerecord,