Forum: Ruby on Rails undefined method `strftime', being called from a partial.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
036be8d5d83a98e546b98d64e3fd6c20?d=identicon&s=25 Sam Donaldson (Guest)
on 2006-05-13 23:42
(Received via mailing list)
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.
43ec5998360a0cc21b51afef1781e9c0?d=identicon&s=25 Daniel Higginbotham (Guest)
on 2006-05-13 23:51
(Received via mailing list)
Try



require 'parsedate'

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

new_time.strftime()



Daniel



  _____

From: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Sam Donaldson
Sent: Saturday, May 13, 2006 11:41 AM
To: rails@lists.rubyonrails.org
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.
This topic is locked and can not be replied to.