Greg Hauptmann
2008-Nov-20 21:22 UTC
should this work? - "validates_inclusion_of :start_date, :in => (Time.now.to_date - 100.years)..(Time.now.to_date + 100.years)"
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
................
tks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Rick
2008-Nov-21 19:22 UTC
Re: should this work? - "validates_inclusion_of :start_date, :in => (Time.now.to_date - 100.years)..(Time.now.to_date + 100.years)"
Greg, 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. My guess is it''s a good thing it didn''t work ;-) Maybe you want to go for a min/max check here. Rick On Nov 20, 11:22 am, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > ................ > > tks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2008-Nov-22 06:08 UTC
Re: should this work? - "validates_inclusion_of :start_date, :in => (Time.now.to_date - 100.years)..(Time.now.to_date + 100.years)"
I''ve actually run with the following:
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
On Sat, Nov 22, 2008 at 5:22 AM, Rick
<Richard.T.Lloyd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Greg,
>
> 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.
>
> My guess is it''s a good thing it didn''t work ;-)
>
> Maybe you want to go for a min/max check here.
>
> Rick
>
> On Nov 20, 11:22 am, "Greg Hauptmann"
<greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
>> 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
>> ................
>>
>> tks
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Rick
2008-Nov-22 11:04 UTC
Re: should this work? - "validates_inclusion_of :start_date, :in => (Time.now.to_date - 100.years)..(Time.now.to_date + 100.years)"
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. Rick On Nov 21, 8:08 pm, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve actually run with the following: > > 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 > > On Sat, Nov 22, 2008 at 5:22 AM, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Greg, > > > 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. > > > My guess is it''s a good thing it didn''t work ;-) > > > Maybe you want to go for a min/max check here. > > > Rick > > > On Nov 20, 11:22 am, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> 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 > >> ................ > > >> tks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick
2008-Nov-22 11:30 UTC
Re: should this work? - "validates_inclusion_of :start_date, :in => (Time.now.to_date - 100.years)..(Time.now.to_date + 100.years)"
Greg - you might take a look at time_with_zone.rb in ActiveSupport - I''m looking at 2.2.0 but I know it''s in 2.1.2 as well. a = Time.now a.is_a?(Time) => true a = "My name is Fred" a.is_a?(Time) => false Maybe closer to what you need? Rick On Nov 22, 1:04 am, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > Rick > > On Nov 21, 8:08 pm, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > I''ve actually run with the following: > > > 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 > > > On Sat, Nov 22, 2008 at 5:22 AM, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Greg, > > > > 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. > > > > My guess is it''s a good thing it didn''t work ;-) > > > > Maybe you want to go for a min/max check here. > > > > Rick > > > > On Nov 20, 11:22 am, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > >> 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 > > >> ................ > > > >> tks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-22 13:26 UTC
Re: should this work? - "validates_inclusion_of :start_date, :in => (Time.now.to_date - 100.years)..(Time.now.to_date + 100.years)"
On 21 Nov 2008, at 19:22, Rick wrote:> > Greg, > > 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 Fred> My guess is it''s a good thing it didn''t work ;-) > > Maybe you want to go for a min/max check here. > > Rick > > On Nov 20, 11:22 am, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> 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 >> ................ >> >> tks > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2008-Nov-22 23:52 UTC
Re: should this work? - "validates_inclusion_of :start_date, :in => (Time.now.to_date - 100.years)..(Time.now.to_date + 100.years)"
thanks - I''m specifically looking at Dates so I might stick with the
below that seems to be working fine...
errors.add(''start_date'', ''is not in Date
format'') if
!start_date.kind_of?(Date)
cheers
On Sat, Nov 22, 2008 at 9:30 PM, Rick
<Richard.T.Lloyd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Greg - you might take a look at time_with_zone.rb in ActiveSupport -
> I''m looking at 2.2.0 but I know it''s in 2.1.2 as well.
>
> a = Time.now
> a.is_a?(Time) => true
> a = "My name is Fred"
> a.is_a?(Time) => false
>
> Maybe closer to what you need?
>
> Rick
>
> On Nov 22, 1:04 am, Rick
<Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> 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.
>>
>> Rick
>>
>> On Nov 21, 8:08 pm, "Greg Hauptmann"
<greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> wrote:
>>
>> > I''ve actually run with the following:
>>
>> > 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
>>
>> > On Sat, Nov 22, 2008 at 5:22 AM, Rick
<Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>
>> > > Greg,
>>
>> > > 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.
>>
>> > > My guess is it''s a good thing it didn''t
work ;-)
>>
>> > > Maybe you want to go for a min/max check here.
>>
>> > > Rick
>>
>> > > On Nov 20, 11:22 am, "Greg Hauptmann"
<greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> > > wrote:
>> > >> 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
>> > >> ................
>>
>> > >> tks
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Rick
2008-Nov-24 21:05 UTC
Re: should this work? - "validates_inclusion_of :start_date, :in => (Time.now.to_date - 100.years)..(Time.now.to_date + 100.years)"
Hello Greg, So here it is. After a couple of mail exchanges with Fred, I need to tell you that I was wrong from the start. Your initial code as given, validates_inclusion_of :start_date, :in => (Time.now.to_date - 100.years)..(Time.now.to_date + 100.years) will work in the case where :start_date is the name of one of your records fields and is a member of the Time class. Sorry if my confused meander wasted too much of your time. Thanks for your help Fred. Rick On Nov 22, 1:52 pm, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> thanks - I''m specifically looking at Dates so I might stick with the > below that seems to be working fine... > > errors.add(''start_date'', ''is not in Date format'') if > !start_date.kind_of?(Date) > > cheers > > On Sat, Nov 22, 2008 at 9:30 PM, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Greg - you might take a look at time_with_zone.rb in ActiveSupport - > > I''m looking at 2.2.0 but I know it''s in 2.1.2 as well. > > > a = Time.now > > a.is_a?(Time) => true > > a = "My name is Fred" > > a.is_a?(Time) => false > > > Maybe closer to what you need? > > > Rick > > > On Nov 22, 1:04 am, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> 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. > > >> Rick > > >> On Nov 21, 8:08 pm, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> wrote: > > >> > I''ve actually run with the following: > > >> > 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 > > >> > On Sat, Nov 22, 2008 at 5:22 AM, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > > Greg, > > >> > > 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. > > >> > > My guess is it''s a good thing it didn''t work ;-) > > >> > > Maybe you want to go for a min/max check here. > > >> > > Rick > > >> > > On Nov 20, 11:22 am, "Greg Hauptmann" <greg.hauptmann.r...@gmail.com> > >> > > wrote: > >> > >> 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 > >> > >> ................ > > >> > >> tks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---