Question about strftime when called from partial

Hi,

I’m calling a helper I’ve written - format_time() that is called from my
views with a given time that was selected from my database and was
returned
to the view via an instance variable. When I call format_time from a
partial, I see that I get some kind of String error and the partial
won’t
render. Basically, the object being passed in to format_time is already
a
string and not in the Time format? Anything special going on with
partials?

Thanks,.

Hello Sam,

2006/5/16, Sam D. [email protected]:

I’m calling a helper I’ve written - format_time() that is called from my
views with a given time that was selected from my database and was returned
to the view via an instance variable. When I call format_time from a
partial, I see that I get some kind of String error and the partial won’t
render. Basically, the object being passed in to format_time is already a
string and not in the Time format? Anything special going on with
partials?

Can you be more specific ? Show us some code ? I do that all the
time, and I have zero problems.

Bye !

So here is the code:

module ApplicationHelper

def format_time(time)
time.strftime("%a %b %d, %I:%M%p")
end
end

and the partial gets the following error;

undefined method `strftime’ for “2006-05-13 15:15:00”:String

So basically it is looking at the object as a String instead of a Time
object which is odd.

Thanks.

I want to add one more thing in case somebody can figure this out, so I
created another helper just for that partial called:

def format_date(time)
new_time = Time.local(*(ParseDate.parsedate(time)))
new_time.strftime("%a %b %d, %I:%M%p")
end

And this worked. So then the question is, why is it that it is coming
back
as a String rather than a Time object. The above code just takes that
string and converts it to a Time object and then does the same
formatting ?

Thanks.

On May 16, 2006, at 9:03 PM, Sam D. wrote:

undefined method `strftime’ for “2006-05-13 15:15:00”:String
So basically it is looking at the object as a String instead of a
Time object which is odd.

Replace that with:

class Time
def format
strtime “%a %b %d, %I:%M%p”
end
end

Then just call format on your Time instance directly.


Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com