Anand Sankaran
2006-Nov-15 04:08 UTC
Date.today throws Invalid Date error only within Rails
I have a weird problem. I have this code in a helper class to the view: today=Date.today and this throws an exception with the message "invalid date" and the stack trace being: /usr/local/lib/ruby/1.8/Date.rb:591:in `new0'' /usr/local/lib/ruby/1.8/date.rb:703:in `today'' Of course, this works outside Rails. Any suggestions why this happens inside Rails? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Anand Sankaran
2006-Nov-16 00:09 UTC
Re: Date.today throws Invalid Date error only within Rails
I have been able to re-create this quite easily in both OS X and in windows. [I thought it could be something to do with incompatible ruby versions in OS X]. So, to reproduce this, all I have to do is this: - Create a new rails app - Create a dummy controller - Create a dummy index method which does this: def index @today=Date.today end - Create a dummy index.rhtml view which prints @today. This works. Now to break it, all I have to do is - add require "Date" [capital "D", require "date" works correctly] It fails immediately at the Date.today line with an invalid date error. Before it fails, it dumps the following in the cmd prompt where webrick is running: c:/ruby/lib/ruby/1.8/Date.rb:238: warning: already initialized constant MONTHNAM ES c:/ruby/lib/ruby/1.8/Date.rb:243: warning: already initialized constant DAYNAMES c:/ruby/lib/ruby/1.8/Date.rb:247: warning: already initialized constant ABBR_MON THNAMES c:/ruby/lib/ruby/1.8/Date.rb:250: warning: already initialized constant ABBR_DAY NAMES c:/ruby/lib/ruby/1.8/Date.rb:254: warning: already initialized constant ITALY c:/ruby/lib/ruby/1.8/Date.rb:258: warning: already initialized constant ENGLAND c:/ruby/lib/ruby/1.8/Date.rb:262: warning: already initialized constant JULIAN c:/ruby/lib/ruby/1.8/Date.rb:266: warning: already initialized constant GREGORIA N In my real app, however, I do not do a require "Date" - so I have no clue what is happening :(. Any ideas? On 11/14/06, Anand Sankaran <anand.sankaran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have a weird problem. I have this code in a helper class to the > view: > > today=Date.today > > and this throws an exception with the message "invalid date" and the > stack trace being: > > /usr/local/lib/ruby/1.8/Date.rb:591:in `new0'' > /usr/local/lib/ruby/1.8/date.rb:703:in `today'' > > Of course, this works outside Rails. Any suggestions why this happens > inside Rails? > >-- anand Photo gallery: http://www.anands.net Photo blog: http://blog.anands.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---