0
如果您分配一個無效的日期(如39月),以日期時間列的ActiveRecord返回「不能爲空」的錯誤時,是應該可能返回一個錯誤,如「不是有效日期」不正確的錯誤
我題。這是預期的導軌行爲,錯誤還是我可以修補的?
class ExerciseLog < ActiveRecord::Base
validates_presence_of :scheduled_datetime
end
啓動控制檯。
e = Log.new
# lets set a date for Dec 39th which obviously doesn't exist
e.scheduled_datetime = "2010-12-39"
e.save
=> false
# this is the confusing message since our form did post a valid date
e.errors.on(:scheduled_datetime)
=> "can't be blank"
e.scheduled_datetime = "2010-12-30"
e.save
=> true
我發現這個問題時,我不小心的月和日值。
順便說一句這是Rails的2.3.5