hi, I need to check dob is greater than today and this is what I did, but I get this error: undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time ++++++++++ class AttendingIp < ActiveRecord::Base ... ... def validate_on_create(today = Date::today) if dob > Date.new(Time.now) errors.add("dob", "Date of birth must be less than " + Time.now.to_formatted_s(:my_format_0) + ".") end end ++++++++++ any ideas? thx, --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 20, 2007 1:50 PM, kimda <kimda-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote:> undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time > > def validate_on_create(today = Date::today) > if dob > Date.new(Time.now)You probably want Date.today or Date.today.to_s depending on what dob is. -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
If I do this: def validate_on_create(today = Date::today) if dob > Date.today errors.add("dob", "Date of birth must be less than " + Time.now.to_formatted_s(:my_format_0) + ".") end end I get this error: You have a nil object when you didn''t expect it! The error occurred while evaluating nil.> On Nov 20, 3:06 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 20, 2007 1:50 PM, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote: > > > undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time > > > def validate_on_create(today = Date::today) > > if dob > Date.new(Time.now) > > You probably want Date.today or Date.today.to_s depending on what dob is. > > -- > Greg Donaldhttp://destiney.com/--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 20 Nov 2007, at 20:11, kimda wrote:> > If I do this: > > def validate_on_create(today = Date::today) > if dob > Date.today > errors.add("dob", "Date of birth must be less than " + > Time.now.to_formatted_s(:my_format_0) + ".") > end > end > > I get this error: > > You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.> >Well if dob is nil then you know what your problem is :-) Fred> > On Nov 20, 3:06 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On Nov 20, 2007 1:50 PM, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote: >> >>> undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time >> >>> def validate_on_create(today = Date::today) >>> if dob > Date.new(Time.now) >> >> You probably want Date.today or Date.today.to_s depending on what >> dob is. >> >> -- >> Greg Donaldhttp://destiney.com/ > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sorry, I forgot to enter date from dob drop down menus. I still get this error: undefined method `/'' for Tue Nov 20 15:38:43 -0500 2007:Time And this prints correct date: puts "dob: " + read_attribute(:dob).to_date.to_s This is the code: def validate_on_create() puts "dob: " + read_attribute(:dob).to_date.to_s if read_attribute(:dob) > Date.new(Time.now) errors.add("dob", "Date of birth must be less than " + Time.now.to_formatted_s(:my_format_0) + ".") end end On Nov 20, 3:19 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 20 Nov 2007, at 20:11, kimda wrote: > > > > > If I do this: > > > def validate_on_create(today = Date::today) > > if dob > Date.today > > errors.add("dob", "Date of birth must be less than " + > > Time.now.to_formatted_s(:my_format_0) + ".") > > end > > end > > > I get this error: > > > You have a nil object when you didn''t expect it! > > The error occurred while evaluating nil.> > > Well if dob is nil then you know what your problem is :-) > > Fred > > > > > On Nov 20, 3:06 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On Nov 20, 2007 1:50 PM, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote: > > >>> undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time > > >>> def validate_on_create(today = Date::today) > >>> if dob > Date.new(Time.now) > > >> You probably want Date.today or Date.today.to_s depending on what > >> dob is. > > >> -- > >> Greg Donaldhttp://destiney.com/--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 20 Nov 2007, at 20:43, kimda wrote:> > Sorry, I forgot to enter date from dob drop down menus. I still get > this error: > undefined method `/'' for Tue Nov 20 15:38:43 -0500 2007:Time > > This is the code: > > def validate_on_create() > puts "dob: " + read_attribute(:dob).to_date.to_s > if read_attribute(:dob) > Date.new(Time.now) > errors.add("dob", "Date of birth must be less than " + > Time.now.to_formatted_s(:my_format_0) + ".") > end > end >Have you checked the documentation for the Date class? If you do you''ll see that Date#new isn''t expecting an instance of Time I''d go with Greg''s suggestion of Date::today Fred> > On Nov 20, 3:19 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 20 Nov 2007, at 20:11, kimda wrote: >> >> >> >>> If I do this: >> >>> def validate_on_create(today = Date::today) >>> if dob > Date.today >>> errors.add("dob", "Date of birth must be less than " + >>> Time.now.to_formatted_s(:my_format_0) + ".") >>> end >>> end >> >>> I get this error: >> >>> You have a nil object when you didn''t expect it! >>> The error occurred while evaluating nil.> >> >> Well if dob is nil then you know what your problem is :-) >> >> Fred >> >> >> >>> On Nov 20, 3:06 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> On Nov 20, 2007 1:50 PM, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote: >> >>>>> undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time >> >>>>> def validate_on_create(today = Date::today) >>>>> if dob > Date.new(Time.now) >> >>>> You probably want Date.today or Date.today.to_s depending on what >>>> dob is. >> >>>> -- >>>> Greg Donaldhttp://destiney.com/ > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I am getting this error: undefined method `-'' for "2007-11-20":String def validate_on_create() puts "dob: " + read_attribute(:dob).to_date.to_s if read_attribute(:dob) > Date.new(Date.today.to_s) errors.add("dob", "Date of birth must be less than " + Time.now.to_formatted_s(:my_format_0) + ".") end end On Nov 20, 3:50 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 20 Nov 2007, at 20:43, kimda wrote: > > > > > Sorry, I forgot to enter date from dob drop down menus. I still get > > this error: > > undefined method `/'' for Tue Nov 20 15:38:43 -0500 2007:Time > > > This is the code: > > > def validate_on_create() > > puts "dob: " + read_attribute(:dob).to_date.to_s > > if read_attribute(:dob) > Date.new(Time.now) > > errors.add("dob", "Date of birth must be less than " + > > Time.now.to_formatted_s(:my_format_0) + ".") > > end > > end > > Have you checked the documentation for the Date class? If you do > you''ll see that Date#new isn''t expecting an instance of Time > I''d go with Greg''s suggestion of Date::today > > Fred > > > > > On Nov 20, 3:19 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 20 Nov 2007, at 20:11, kimda wrote: > > >>> If I do this: > > >>> def validate_on_create(today = Date::today) > >>> if dob > Date.today > >>> errors.add("dob", "Date of birth must be less than " + > >>> Time.now.to_formatted_s(:my_format_0) + ".") > >>> end > >>> end > > >>> I get this error: > > >>> You have a nil object when you didn''t expect it! > >>> The error occurred while evaluating nil.> > > >> Well if dob is nil then you know what your problem is :-) > > >> Fred > > >>> On Nov 20, 3:06 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>>> On Nov 20, 2007 1:50 PM, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote: > > >>>>> undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time > > >>>>> def validate_on_create(today = Date::today) > >>>>> if dob > Date.new(Time.now) > > >>>> You probably want Date.today or Date.today.to_s depending on what > >>>> dob is. > > >>>> -- > >>>> Greg Donaldhttp://destiney.com/--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 20 Nov 2007, at 20:59, kimda wrote:> > I am getting this error: undefined method `-'' for "2007-11-20":String > > def validate_on_create() > puts "dob: " + read_attribute(:dob).to_date.to_s > if read_attribute(:dob) > Date.new(Date.today.to_s) > errors.add("dob", "Date of birth must be less than " + > Time.now.to_formatted_s(:my_format_0) + ".") > end > end >Date.new doesn''t take a string either. Why are you complicating this beyond dob > Date.today ? Fred> On Nov 20, 3:50 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 20 Nov 2007, at 20:43, kimda wrote: >> >> >> >>> Sorry, I forgot to enter date from dob drop down menus. I still get >>> this error: >>> undefined method `/'' for Tue Nov 20 15:38:43 -0500 2007:Time >> >>> This is the code: >> >>> def validate_on_create() >>> puts "dob: " + read_attribute(:dob).to_date.to_s >>> if read_attribute(:dob) > Date.new(Time.now) >>> errors.add("dob", "Date of birth must be less than " + >>> Time.now.to_formatted_s(:my_format_0) + ".") >>> end >>> end >> >> Have you checked the documentation for the Date class? If you do >> you''ll see that Date#new isn''t expecting an instance of Time >> I''d go with Greg''s suggestion of Date::today >> >> Fred >> >> >> >>> On Nov 20, 3:19 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> wrote: >>>> On 20 Nov 2007, at 20:11, kimda wrote: >> >>>>> If I do this: >> >>>>> def validate_on_create(today = Date::today) >>>>> if dob > Date.today >>>>> errors.add("dob", "Date of birth must be less than " + >>>>> Time.now.to_formatted_s(:my_format_0) + ".") >>>>> end >>>>> end >> >>>>> I get this error: >> >>>>> You have a nil object when you didn''t expect it! >>>>> The error occurred while evaluating nil.> >> >>>> Well if dob is nil then you know what your problem is :-) >> >>>> Fred >> >>>>> On Nov 20, 3:06 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>> On Nov 20, 2007 1:50 PM, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote: >> >>>>>>> undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time >> >>>>>>> def validate_on_create(today = Date::today) >>>>>>> if dob > Date.new(Time.now) >> >>>>>> You probably want Date.today or Date.today.to_s depending on what >>>>>> dob is. >> >>>>>> -- >>>>>> Greg Donaldhttp://destiney.com/ > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I already tried that and I got: comparison of Date with Time failed On Nov 20, 4:05 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 20 Nov 2007, at 20:59, kimda wrote: > > > > > I am getting this error: undefined method `-'' for "2007-11-20":String > > > def validate_on_create() > > puts "dob: " + read_attribute(:dob).to_date.to_s > > if read_attribute(:dob) > Date.new(Date.today.to_s) > > errors.add("dob", "Date of birth must be less than " + > > Time.now.to_formatted_s(:my_format_0) + ".") > > end > > end > > Date.new doesn''t take a string either. Why are you complicating this > beyond dob > Date.today ? > > Fred > > > On Nov 20, 3:50 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 20 Nov 2007, at 20:43, kimda wrote: > > >>> Sorry, I forgot to enter date from dob drop down menus. I still get > >>> this error: > >>> undefined method `/'' for Tue Nov 20 15:38:43 -0500 2007:Time > > >>> This is the code: > > >>> def validate_on_create() > >>> puts "dob: " + read_attribute(:dob).to_date.to_s > >>> if read_attribute(:dob) > Date.new(Time.now) > >>> errors.add("dob", "Date of birth must be less than " + > >>> Time.now.to_formatted_s(:my_format_0) + ".") > >>> end > >>> end > > >> Have you checked the documentation for the Date class? If you do > >> you''ll see that Date#new isn''t expecting an instance of Time > >> I''d go with Greg''s suggestion of Date::today > > >> Fred > > >>> On Nov 20, 3:19 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >>> wrote: > >>>> On 20 Nov 2007, at 20:11, kimda wrote: > > >>>>> If I do this: > > >>>>> def validate_on_create(today = Date::today) > >>>>> if dob > Date.today > >>>>> errors.add("dob", "Date of birth must be less than " + > >>>>> Time.now.to_formatted_s(:my_format_0) + ".") > >>>>> end > >>>>> end > > >>>>> I get this error: > > >>>>> You have a nil object when you didn''t expect it! > >>>>> The error occurred while evaluating nil.> > > >>>> Well if dob is nil then you know what your problem is :-) > > >>>> Fred > > >>>>> On Nov 20, 3:06 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>>>>> On Nov 20, 2007 1:50 PM, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote: > > >>>>>>> undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time > > >>>>>>> def validate_on_create(today = Date::today) > >>>>>>> if dob > Date.new(Time.now) > > >>>>>> You probably want Date.today or Date.today.to_s depending on what > >>>>>> dob is. > > >>>>>> -- > >>>>>> Greg Donaldhttp://destiney.com/--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 20, 2007 3:13 PM, kimda <kimda-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote:> > I already tried that and I got: > > comparison of Date with Time failedWhy is dob a Time and not a date? -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 20, 2007, at 3:13 PM, kimda wrote:> I already tried that and I got: > > comparison of Date with Time faileddob = Date.new(2007,11,21) => #<Date: 4908851/2,0,2299161> >> dob > Date.today => true --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 20 Nov 2007, at 21:13, kimda wrote:> > I already tried that and I got: > > comparison of Date with Time failed >This is so circular. Why not do dob > Time.now then ? (or Time.now.midnight) Fred> > > On Nov 20, 4:05 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 20 Nov 2007, at 20:59, kimda wrote: >> >> >> >>> I am getting this error: undefined method `-'' for >>> "2007-11-20":String >> >>> def validate_on_create() >>> puts "dob: " + read_attribute(:dob).to_date.to_s >>> if read_attribute(:dob) > Date.new(Date.today.to_s) >>> errors.add("dob", "Date of birth must be less than " + >>> Time.now.to_formatted_s(:my_format_0) + ".") >>> end >>> end >> >> Date.new doesn''t take a string either. Why are you complicating this >> beyond dob > Date.today ? >> >> Fred >> >>> On Nov 20, 3:50 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> wrote: >>>> On 20 Nov 2007, at 20:43, kimda wrote: >> >>>>> Sorry, I forgot to enter date from dob drop down menus. I still >>>>> get >>>>> this error: >>>>> undefined method `/'' for Tue Nov 20 15:38:43 -0500 2007:Time >> >>>>> This is the code: >> >>>>> def validate_on_create() >>>>> puts "dob: " + read_attribute(:dob).to_date.to_s >>>>> if read_attribute(:dob) > Date.new(Time.now) >>>>> errors.add("dob", "Date of birth must be less than " + >>>>> Time.now.to_formatted_s(:my_format_0) + ".") >>>>> end >>>>> end >> >>>> Have you checked the documentation for the Date class? If you do >>>> you''ll see that Date#new isn''t expecting an instance of Time >>>> I''d go with Greg''s suggestion of Date::today >> >>>> Fred >> >>>>> On Nov 20, 3:19 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>>>> wrote: >>>>>> On 20 Nov 2007, at 20:11, kimda wrote: >> >>>>>>> If I do this: >> >>>>>>> def validate_on_create(today = Date::today) >>>>>>> if dob > Date.today >>>>>>> errors.add("dob", "Date of birth must be less than " + >>>>>>> Time.now.to_formatted_s(:my_format_0) + ".") >>>>>>> end >>>>>>> end >> >>>>>>> I get this error: >> >>>>>>> You have a nil object when you didn''t expect it! >>>>>>> The error occurred while evaluating nil.> >> >>>>>> Well if dob is nil then you know what your problem is :-) >> >>>>>> Fred >> >>>>>>> On Nov 20, 3:06 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>> On Nov 20, 2007 1:50 PM, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> >>>>>>>> wrote: >> >>>>>>>>> undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time >> >>>>>>>>> def validate_on_create(today = Date::today) >>>>>>>>> if dob > Date.new(Time.now) >> >>>>>>>> You probably want Date.today or Date.today.to_s depending on >>>>>>>> what >>>>>>>> dob is. >> >>>>>>>> -- >>>>>>>> Greg Donaldhttp://destiney.com/ > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 20, 2007, at 1:50 PM, kimda wrote:> > hi, > > I need to check dob is greater than today and this is what I did, but > I get this error: > > undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time > > ++++++++++ > class AttendingIp < ActiveRecord::Base > ... > ... > def validate_on_create(today = Date::today) > if dob > Date.new(Time.now) > errors.add("dob", "Date of birth must be less than " + > Time.now.to_formatted_s(:my_format_0) + ".") > end > end > ++++++++++ > any ideas?Assuming dob is a Date, and not a Time, then you could write it this way: def validate_on_create errors.add("dob", "Date of birth must not be in the future.") if dob > Date.today end if dob is a Time but you''re not actually concerned about the time of day, then this will work: def validate_on_create errors.add("dob", "Date of birth must not be in the future.") if dob.to_date > Date.today end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I found out that as long as I enter DOB(from new form), I get same error no matter what. Even if I do this: dob1 = Date.new(2007,11,21) dob2 = Date.new(2006,11,21) if dob1 > dob2 This is the line that error message indicates and I don''t understand why this always gives error no matter what I do in that def. Showing app/views/attending_ips/_form.rhtml where line #14 raised: ..l. ... <TD valign=top><FONT COLOR="151b8d" FACE="arial,geneva,helvetica" SIZE="-1"><B>DOB</B><FONT SIZE="-2"> (mm/dd/yyyy)<BR><%= date_select ''attending_ip'', ''dob'', :order => [:month, :day, :year], :use_month_numbers => true, :include_blank => true, :start_year => 1970, :end_year => Time.now.year %> Have I done something wrong in this view? On Nov 20, 4:21 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 20 Nov 2007, at 21:13, kimda wrote: > > > > > I already tried that and I got: > > > comparison of Date with Time failed > > This is so circular. Why not do dob > Time.now then ? (or > Time.now.midnight) > > Fred > > > > > On Nov 20, 4:05 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 20 Nov 2007, at 20:59, kimda wrote: > > >>> I am getting this error: undefined method `-'' for > >>> "2007-11-20":String > > >>> def validate_on_create() > >>> puts "dob: " + read_attribute(:dob).to_date.to_s > >>> if read_attribute(:dob) > Date.new(Date.today.to_s) > >>> errors.add("dob", "Date of birth must be less than " + > >>> Time.now.to_formatted_s(:my_format_0) + ".") > >>> end > >>> end > > >> Date.new doesn''t take a string either. Why are you complicating this > >> beyond dob > Date.today ? > > >> Fred > > >>> On Nov 20, 3:50 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >>> wrote: > >>>> On 20 Nov 2007, at 20:43, kimda wrote: > > >>>>> Sorry, I forgot to enter date from dob drop down menus. I still > >>>>> get > >>>>> this error: > >>>>> undefined method `/'' for Tue Nov 20 15:38:43 -0500 2007:Time > > >>>>> This is the code: > > >>>>> def validate_on_create() > >>>>> puts "dob: " + read_attribute(:dob).to_date.to_s > >>>>> if read_attribute(:dob) > Date.new(Time.now) > >>>>> errors.add("dob", "Date of birth must be less than " + > >>>>> Time.now.to_formatted_s(:my_format_0) + ".") > >>>>> end > >>>>> end > > >>>> Have you checked the documentation for the Date class? If you do > >>>> you''ll see that Date#new isn''t expecting an instance of Time > >>>> I''d go with Greg''s suggestion of Date::today > > >>>> Fred > > >>>>> On Nov 20, 3:19 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >>>>> wrote: > >>>>>> On 20 Nov 2007, at 20:11, kimda wrote: > > >>>>>>> If I do this: > > >>>>>>> def validate_on_create(today = Date::today) > >>>>>>> if dob > Date.today > >>>>>>> errors.add("dob", "Date of birth must be less than " + > >>>>>>> Time.now.to_formatted_s(:my_format_0) + ".") > >>>>>>> end > >>>>>>> end > > >>>>>>> I get this error: > > >>>>>>> You have a nil object when you didn''t expect it! > >>>>>>> The error occurred while evaluating nil.> > > >>>>>> Well if dob is nil then you know what your problem is :-) > > >>>>>> Fred > > >>>>>>> On Nov 20, 3:06 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>>>>>>> On Nov 20, 2007 1:50 PM, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> > >>>>>>>> wrote: > > >>>>>>>>> undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time > > >>>>>>>>> def validate_on_create(today = Date::today) > >>>>>>>>> if dob > Date.new(Time.now) > > >>>>>>>> You probably want Date.today or Date.today.to_s depending on > >>>>>>>> what > >>>>>>>> dob is. > > >>>>>>>> -- > >>>>>>>> Greg Donaldhttp://destiney.com/--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
As I mentioned like below, I get same error. The only difference in that error message is that if I use your first way, error message comes from model, If I try second, it comes from view. On Nov 20, 4:44 pm, George Bailey <listcatc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 20, 2007, at 1:50 PM, kimda wrote: > > > > > > > hi, > > > I need to check dob is greater than today and this is what I did, but > > I get this error: > > > undefined method `/'' for Tue Nov 20 14:21:26 -0500 2007:Time > > > ++++++++++ > > class AttendingIp < ActiveRecord::Base > > ... > > ... > > def validate_on_create(today = Date::today) > > if dob > Date.new(Time.now) > > errors.add("dob", "Date of birth must be less than " + > > Time.now.to_formatted_s(:my_format_0) + ".") > > end > > end > > ++++++++++ > > any ideas? > > Assuming dob is a Date, and not a Time, then you could write it this > way: > > def validate_on_create > errors.add("dob", "Date of birth must not be in the future.") > if dob > Date.today > end > > if dob is a Time but you''re not actually concerned about the time of > day, then this will work: > > def validate_on_create > errors.add("dob", "Date of birth must not be in the future.") > if dob.to_date > Date.today > end--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 20, 2007, at 4:08 PM, kimda wrote:> As I mentioned like below, I get same error. The only difference in > that error message is that if I use your first way, error message > comes from model, If I try second, it comes from view.If you''re getting an error it must be that dob is not what you think it is. Can you post your view and controller code? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
def create @attending_ip = AttendingIp.new(params[:attending_ip]) @attending_ip.last_name = @attending_ip.last_name.upcase @attending_ip.first_name = @attending_ip.first_name.upcase if @attending_ip.save flash[:notice] = ''Patient record was successfully created.'' redirect_to :action => ''search'' else render :action => ''new'' end end ++++++++++++ new.rhtml <h1>Create new inpatient Sign-Out Database Inpatient Information</h1> <% form_tag :action => ''create'' do %> <%= render :partial => ''form'' %> <%= submit_tag "Create" %> <INPUT TYPE="reset" VALUE="Restore Original"> <br><A NAME="print"> <FONT COLOR="1528c7" FACE="arial,geneva,helvetica" SIZE="-2">** PRINT not available until a patient is created **</FONT> <%= render :partial => "attending_ips/menu" %> <% end %> +++++++++++++++ _form.rhtml ... ... <TD valign=top><FONT COLOR="151b8d" FACE="arial,geneva,helvetica" SIZE="-1"><B>DOB</B><FONT SIZE="-2"> (mm/dd/yyyy)<BR><%= date_select ''attending_ip'', ''dob'', :order => [:month, :day, :year], :use_month_numbers => true, :include_blank => true, :start_year => 1970, :end_year => Time.now.year %> ... ... On Nov 20, 5:15 pm, George Bailey <listcatc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 20, 2007, at 4:08 PM, kimda wrote: > > > As I mentioned like below, I get same error. The only difference in > > that error message is that if I use your first way, error message > > comes from model, If I try second, it comes from view. > > If you''re getting an error it must be that dob is not what you think > it is. > Can you post your view and controller code?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I found the error. Actually, it was coming from other def and I didn''t realized that. Thanks for all your help! On Nov 20, 5:30 pm, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote:> def create > > @attending_ip = AttendingIp.new(params[:attending_ip]) > @attending_ip.last_name = @attending_ip.last_name.upcase > @attending_ip.first_name = @attending_ip.first_name.upcase > if @attending_ip.save > flash[:notice] = ''Patient record was successfully created.'' > redirect_to :action => ''search'' > else > render :action => ''new'' > end > end > > ++++++++++++ > > new.rhtml > > <h1>Create new inpatient Sign-Out Database Inpatient Information</h1> > > <% form_tag :action => ''create'' do %> > <%= render :partial => ''form'' %> > <%= submit_tag "Create" %> > <INPUT TYPE="reset" VALUE="Restore Original"> > > <br><A NAME="print"> > <FONT COLOR="1528c7" FACE="arial,geneva,helvetica" SIZE="-2">** PRINT > not available until a patient is created **</FONT> > > <%= render :partial => "attending_ips/menu" %> > <% end %> > > +++++++++++++++ > > _form.rhtml > > ... > ... > <TD valign=top><FONT COLOR="151b8d" FACE="arial,geneva,helvetica" > SIZE="-1"><B>DOB</B><FONT SIZE="-2"> (mm/dd/yyyy)<BR><%= date_select > ''attending_ip'', ''dob'', :order => > [:month, :day, :year], :use_month_numbers => true, :include_blank => > true, :start_year => 1970, :end_year => Time.now.year %> > ... > ... > > On Nov 20, 5:15 pm, George Bailey <listcatc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Nov 20, 2007, at 4:08 PM, kimda wrote: > > > > As I mentioned like below, I get same error. The only difference in > > > that error message is that if I use your first way, error message > > > comes from model, If I try second, it comes from view. > > > If you''re getting an error it must be that dob is not what you think > > it is. > > Can you post your view and controller code?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
A simpler option could be just have this in your view template which will only display dates from today onwards <%= date_select(:person, "dob", :start_year => Time.now.strftime("%Y").to_i, :end_year => 1950) %> On Nov 21, 4:24 pm, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote:> I found the error. Actually, it was coming from other def and I didn''t > realized that. Thanks for all your help! > > On Nov 20, 5:30 pm, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote: > > > def create > > > @attending_ip = AttendingIp.new(params[:attending_ip]) > > @attending_ip.last_name = @attending_ip.last_name.upcase > > @attending_ip.first_name = @attending_ip.first_name.upcase > > if @attending_ip.save > > flash[:notice] = ''Patient record was successfully created.'' > > redirect_to :action => ''search'' > > else > > render :action => ''new'' > > end > > end > > > ++++++++++++ > > > new.rhtml > > > <h1>Create new inpatient Sign-Out Database Inpatient Information</h1> > > > <% form_tag :action => ''create'' do %> > > <%= render :partial => ''form'' %> > > <%= submit_tag "Create" %> > > <INPUT TYPE="reset" VALUE="Restore Original"> > > > <br><A NAME="print"> > > <FONT COLOR="1528c7" FACE="arial,geneva,helvetica" SIZE="-2">** PRINT > > not available until a patient is created **</FONT> > > > <%= render :partial => "attending_ips/menu" %> > > <% end %> > > > +++++++++++++++ > > > _form.rhtml > > > ... > > ... > > <TD valign=top><FONT COLOR="151b8d" FACE="arial,geneva,helvetica" > > SIZE="-1"><B>DOB</B><FONT SIZE="-2"> (mm/dd/yyyy)<BR><%= date_select > > ''attending_ip'', ''dob'', :order => > > [:month, :day, :year], :use_month_numbers => true, :include_blank => > > true, :start_year => 1970, :end_year => Time.now.year %> > > ... > > ... > > > On Nov 20, 5:15 pm, George Bailey <listcatc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Nov 20, 2007, at 4:08 PM, kimda wrote: > > > > > As I mentioned like below, I get same error. The only difference in > > > > that error message is that if I use your first way, error message > > > > comes from model, If I try second, it comes from view. > > > > If you''re getting an error it must be that dob is not what you think > > > it is. > > > Can you post your view and controller code?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---