【问题标题】:Error using strftime on hour in rails在 Rails 中按小时使用 strftime 时出错
【发布时间】: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


【解决方案1】:

原来“Aulas”都是空的。 谢谢戴夫牛顿

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2014-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    相关资源
    最近更新 更多