Okay so September has 30 days right.
This is what rails does when you set an invalid date like 31 September:
s = Student.first
s.date_of_birth = "2015-09-31"
s.save!
> true
s.date_of_birth
> Thu, 01 Oct 2015 00:00:00 UTC +00:00
It sets the date to 1st of October.
What I want is something like this
s.save!
(0.4ms) BEGIN
(0.5ms) ROLLBACK
ActiveRecord::RecordInvalid: Validation failed: Date is not a valid date
Is there no way to force Rails to explicitly error out when setting such a crap date? The standard rails date_select
does not dynamically change the number of days in the days dropdown when you change to a different month. So you can select 31 September with the dropdowns, and the date will be saved as 1st of October. But I want to display an error message.
I don't want people to accidentally put the wrong dates into my system.