2013-11-14 26 views
-1

在我的索引中我有@ date.day,当我使用@ date.strftime(“%B%Y”)时,它工作得很好。在rails中使用strftime时出错

但是在代码中还有一个小问题,我有aula.time2。 它让我喜欢“2000-01-01 10:00:00 UTC”,这是丑陋的。 但如果我尝试打印aula.time2.strftime(“%I%M”)它不会工作。

它给了我这个错误: 未定义的方法`strftime的”为无:NilClass

什么想法?

指数:

<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 %> 
+0

你确定所有的aulas不是零? –

+0

是的。就是这样! 谢谢你! – Allan

回答

0

它竟然是认为, “奥拉” 都是nill。 感谢戴夫牛顿