My code looks like:
if f.thisyear.blank? && Date.new(Date.today.year, f.birthday.month, f.birthday.mday ).valid_date?
f.update_attribute :thisyear, Date.new(Date.today.year, f.birthday.month, f.birthday.mday )
end
In the first line, I check for a valid date using:
Date.new(Date.today.year, f.birthday.month, f.birthday.mday ).valid_date?
This throws an error:
`new': invalid date (ArgumentError)
How do I have to write my code to avoid this problem?
Date::valid_date?
is a class method, so instead of
Date.new(Date.today.year, f.birthday.month, f.birthday.mday).valid_date?
use
Date.valid_date?(Date.today.year, f.birthday.month, f.birthday.mday)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With