我不能設置user.fee_email = -1
,但即使在我的模型中指定的fee_email
應該是正數,我也可以。Rails:驗證greater_than_or_equal_to 0不起作用
考慮:
class User < ActiveRecord::Base
validates :fee_email, numericality: { greater_than_or_equal_to: 0 }
...
end
這不應該發生:
2.2.1 :002 > a = User.first
2.2.1 :003 > a.fee_email
=> #<BigDecimal:43cbbe0,'0.0',9(27)>
2.2.1 :004 > a.fee_email = -1
=> -1
2.2.1 :005 > a.fee_email
=> #<BigDecimal:43b5688,'-0.1E1',9(27)>