用于“2013-03-06"的 Rails 未定义方法“strftime":字符串 [英] Rails undefined method `strftime' for "2013-03-06":String
问题描述
我收到错误
未定义方法`strftime' for "2013-03-06":String
undefined method `strftime' for "2013-03-06":String
尝试使用 strftime 从字符串 2013-03-06 中正常显示日期(2013 年 6 月 3 日或类似日期)时.
when trying to display a date normally (June Sunday 3, 2013 or something similar) from the string 2013-03-06 using strftime.
在我的 index.html.erb 中执行此操作的行看起来像这样
The line that does this in my index.html.erb and looks like this
<%= task.duedate.strftime("%B %e, %Y") %>
我只是在学习 Rails,所以我确定这只是一个愚蠢的初学者错误,任何帮助将不胜感激.谢谢
I am just learning Rails so I am sure it is just a stupid beginners error, any help would be appreciated. Thank you
推荐答案
当 strftime 是 Time/Date 类的方法时,它看起来像是一个字符串.你可以试试这个:
It looks like your duedate is a string, when strftime is a method for Time/Date class. You can try this:
Date.parse(task.duedate).strftime("%B %e, %Y")
这篇关于用于“2013-03-06"的 Rails 未定义方法“strftime":字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!