wondering if should this work? - "validates_inclusion_of :start_date,
:in => (Time.now.to_date - 100.years)..(Time.now.to_date + 100.years)"
(doesn't seem to for me)
i.e. should I be able to "validates_inclusion_of" to do date validation.
................
class GraphOptions < ActiveRecord::BaseWithoutTable
column :start_date, :date
validates_inclusion_of :start_date, :in => (Time.now.to_date -
100.years)..(Time.now.to_date + 100.years)
end
................
validates_inclusion_of is looking for :in to be an enumeration. In a
simple case (one day granularity) you're asking for a list that's
365.25 * 200 => 73050 items long.
def validate
errors.add('start_date', 'is not in Date format') if
!start_date.kind_of?(Date)
errors.add('end_date', 'is not in Date format') if !end_date.kind_of?(Date)
end
Its seems that the Rails controller tries to convert it to Date and
either succeeds or fails (without throwing an exception). So I just
test to see at the subsequent validate stage whether there is a Date
object or not
Right, but back to your initial question, I don't think my initial
answer was even close to the mark.
I believe the problem you're having is that the validates_inclusion is
looking for an enumeration hanging off the :in. i.e. [1,2,3,4,5] or
1..5 will work but (My Name Is Frank)..(Your Name Is Louie) somehow
doesn't look right, does it?
You're doing :in => (Sun, 22 Nov 1908)..(Sun, 22 Nov 2108)
which just isn't going to happen. Try converting to Julian days, that
way you'll be bounded with two positive integers.
validates_inclusion_of is looking for :in to be an enumeration. In a
simple case (one day granularity) you're asking for a list that's
365.25 * 200 => 73050 items long.
ranges are enumerable and ruby is smart enough to keep it as a range, eg
r = (-1000000000..1000000000)
does not create a 2 billion element array