Sam Donaldson
2006-May-16 19:22 UTC
[Rails] 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,. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060516/f06c35bc/attachment.html
Francois Beausoleil
2006-May-16 23:46 UTC
[Rails] question about strftime when called from partial.
Hello Sam, 2006/5/16, Sam Donaldson <samonderous@gmail.com>:> 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 ! -- Fran?ois Beausoleil http://blog.teksol.info/
Sam Donaldson
2006-May-17 04:03 UTC
[Rails] question about strftime when called from partial.
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.
On 5/16/06, Francois Beausoleil <francois.beausoleil@gmail.com>
wrote:>
> Hello Sam,
>
> 2006/5/16, Sam Donaldson <samonderous@gmail.com>:
> > 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 !
> --
> Fran?ois Beausoleil
> http://blog.teksol.info/
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060517/802d8a1e/attachment-0001.html
Sam Donaldson
2006-May-17 04:19 UTC
[Rails] question about strftime when called from partial.
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 5/16/06, Sam Donaldson <samonderous@gmail.com>
wrote:>
> 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.
>
>
> On 5/16/06, Francois Beausoleil <francois.beausoleil@gmail.com>
wrote:
>
> > Hello Sam,
>
> 2006/5/16, Sam Donaldson <samonderous@gmail.com >:
> > 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 !
> --
> Fran?ois Beausoleil
> http://blog.teksol.info/
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060517/e2fa010b/attachment.html
Eric Hodel
2006-May-17 18:00 UTC
[Rails] question about strftime when called from partial.
On May 16, 2006, at 9:03 PM, Sam Donaldson wrote:> 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.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 Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com