A user enters two dates. On before_save, I’m trying to validate that
the second date does not come before the first.
Assume that start_date and end_date are Datetime objects. If I call
the following method from the model on before_save, why is no error
added to end_date?
start = Time.at(self.start_date)
last = Time.at(self.end_date)
if (start - last) > 0
errors.add(:base, “can’t come before start date”)
I know know that this code is quite ugly. I could not get the
Datetime objects to compare any other way.
Anyone who can make this code beautiful and functional is awesome.