I am building an application and I have generated the scaffold for a product. In the list method I include something like my_date = Datetime.now and the result I get from the webrick is an error uninitialized constant Datetime Do I have to add a line with a require? I am new at ruby on rails thanks in advance -- Posted via http://www.ruby-forum.com/.
enrique barraorion wrote:> I am building an application and I have generated the scaffold for a > product. > In the list method I include something like > my_date = Datetime.now > > and the result I get from the webrick is an error > > uninitialized constant Datetime > > Do I have to add a line with a require? > I am new at ruby on railsRuby is case-sensitive. The name of the class is DateTime. You''ll also need to require ''date'' in order to use it. You may like to consider using the faster Time class instead of DateTime. The only real problem with Time is that on some platforms it cannot handle dates earlier than 1970 or later than 2037. -- Philip Ross http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
On Sun, 2006-06-18 at 14:36 +0200, enrique barraorion wrote:> I am building an application and I have generated the scaffold for a > product. > In the list method I include something like > my_date = Datetime.now > > and the result I get from the webrick is an error > > uninitialized constant Datetime > > Do I have to add a line with a require? > I am new at ruby on rails---- no - I think you should try, DateTime.now Craig
Craig White wrote:> On Sun, 2006-06-18 at 14:36 +0200, enrique barraorion wrote: >> I am new at ruby on rails > ---- > no - I think you should try, DateTime.now > > CraigOk thanks, i did not know it was case sensitive. but I still have a problem, I am trying to select from a mysql database events from a start_date to a end_date (columns that are of type timestamp) and I do: datetime_start_day = DateTime.now datetime_end_day = datetime_start_day +1 EventDatetime.find_all(:conditions => ["start_date > ? AND end_date < ?", datetime_start_day, datetime_end_day]) end Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''? AND end_date < ?2006-06-18T19:49:02+02002006-06-19T19:49:02+0200)'' at line 1: SELECT * FROM event_datetimes WHERE (conditionsstart_date > ? AND end_date < ?2006-06-18T19:49:02+02002006-06-19T19:49:02+0200) -- Posted via http://www.ruby-forum.com/.