Topic: ActiveRecord thinks date/time fields are strings

Every now and then (more now than then), I get an error in my .rhtml page when processing a datetime field using "strftime", as follows:

undefined method `strftime' for "2007-01-17 14:26:07 -0500":String

Why would activerecord think the field is a string?  (The field is indeed a date/time field...I verified this in the database).

And this only happens sometimes?

Thx for the help.

Re: ActiveRecord thinks date/time fields are strings

Not sure, can you post the code which is calling strftime? I'm assuming you don't have a method in the model with the same name which could be overriding this call to the column?

Are you ever assigning a string to this column during the same request? Maybe Rails isn't converting it to a Time object before it is read again (it should be though...).

Railscasts - Free Ruby on Rails Screencasts

Re: ActiveRecord thinks date/time fields are strings

<%= @profile.DateModified.nil? ? "not updated" : @profile.DateModified.strftime("%m/%d/%y %I:%M%p").downcase() %>

I checked the code and I was setting it to "" when the record is first created.  I'm going to try nil instead, and see if I receive the error again.  This is happening on 3 of my datetime fields so far.

Last edited by blakeage (2007-01-18 15:22:27)