Undefined method `strftime', being called from a partial


#1

Hi,

I’m having an issue with calling a function that I’ve defined in
ApplicationHelper called format_time:

module ApplicationHelper

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

end

I use this function in my views to format the Time.now that I would have
stored in my tables as a DATETIME. I’m able to use this function,
without
any issues from my views, but if I try using it from a partial, I guess
the
following error:

undefined method `strftime’ for “2006-05-12 21:31:48”:String

I guess the problem is that the time is coming in as a String into
format_time, when it should be of type Time.

Thanks in advance.


#2

Try

require ‘parsedate’

new_time = Time.local(ParseDate.parsedate(time))

new_time.strftime()

Daniel


From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Sam D.
Sent: Saturday, May 13, 2006 11:41 AM
To: removed_email_address@domain.invalid
Subject: [Rails] undefined method `strftime’, being called from a
partial.

Hi,

I’m having an issue with calling a function that I’ve defined in
ApplicationHelper called format_time:

module ApplicationHelper

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

end

I use this function in my views to format the Time.now that I would have
stored in my tables as a DATETIME. I’m able to use this function,
without
any issues from my views, but if I try using it from a partial, I guess
the
following error:

undefined method `strftime’ for “2006-05-12 21:31:48”:String

I guess the problem is that the time is coming in as a String into
format_time, when it should be of type Time.

Thanks in advance.