【发布时间】:2013-11-27 19:06:32
【问题描述】:
在我的索引中我有@date.day,当我使用@date.strftime("%B %Y") 时,它工作得很好。
但在代码中更进一步,我有 aula.time2。 它给了我像“2000-01-01 10:00:00 UTC”这样的丑陋。 但是如果我尝试打印 aula.time2.strftime("%I %M") 它将不起作用。
它给了我这个错误: nil:NilClass 的未定义方法 `strftime'
有什么想法吗?
索引:
<div id="articles">
<h2 id="month">
<%= link_to "<", date: @date.prev_week %>
<%= @date.strftime("%B %Y") %>
<%= link_to ">", date: @date.next_week%>
</h2>
<%= calendar @date do |date| %>
<%= date.day %>
<% if @aulas_by_date[date] %>
<ul>
<% @aulas_by_date[date].each do |aula| %>
<%= aula.time2.strftime("%I %M") %>
</div>
<% end %>
</ul>
<% end %>
<% end %>
【问题讨论】:
-
你确定所有的 aulas 都不为零?
-
是的。就是这样!谢谢大佬!
标签: ruby-on-rails time strftime