I would like to write inclusion validator like below:
validates :application_date,
inclusion_of: { in: Date.today..20.years.from_now }
# Schema
# application_date :date
But I get
bad value for range
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The reason you’re getting that error is because
20.years.from_nowis returning a datetime object (ActiveSupport::TimeWithZone) andDate.todayreturns a date. Therefor your range will not work because it’s using two different object types. You might be able to fix it by converting the latter to a date: