I have a custom validation method that ensures an alarm can only be set in the future..
class Alarm < ActiveRecord::Base
validate :alarm_set_in_the_future
def alarm_set_in_the_future
if time <= DateTime.current
errors.add(:alarm, "Please Choose A Future Date & Time")
end
end
This works great and the tests pass upon creating a new Alarm record. Awesome…
However, when editing an Alarm, the time variable gets set to the following datetime and I have no idea why!
2000-01-01 03:28:00 UTC
Consequently, the validation fails.
Where is that time parameter getting reset? Help!
Take a look at what’s being submitted from your form. It seems unlikely that the problem lies in the validation itself.
Most likely, you’re getting some bogus data from the form when saving the record. What is the value of
@alarm.timein the controller before you save? What does theparamshash look like?