I have several models with a date attribute, and for each model I would like to confirm these dates for a given range. Basic example:
validates_inclusion_of :dated_on, :in => Date.new(2000,1,1)..Date(2020,1,1)
Ideally, I would like to evaluate the date range at runtime using a similar approach, for example named_scope, for example:
validates_inclusion_of :dated_on, :in => lambda {{ (Date.today - 2.years)..(Date.today + 2.years)}}
The above doesn't work, of course, so what's the best way to achieve the same result?
source
share