If user inserts a value that is not accepted to the to_date
method, e.g. "some gibberish", it returns:
"ArgumentError: invalid date"
How could I construct a custom validation that returns an validation message to user and doesn't halts the application?
I was thinking that reusing the code from another answer would be a good idea, but I don't know how to apply it to to_date
.
validate do
self.errors[:start] << "must be a valid date" unless DateTime.parse(self.start) rescue false
end