【发布时间】:2015-03-08 20:02:52
【问题描述】:
我遇到了一个奇怪的问题。在我的 Rails 应用程序中,执行:time_ago_in_words homework.created_at 返回错误:
undefined method `>' for nil:NilClass
上下文:
<h3 class="media-heading"><%= homework.title %></h3>
<p>Assigned <%= time_ago_in_words homework.created_at %> ago</p>
created_at 已定义,此迁移 t.timestamps null: false(是的,我已经运行了它),它在数据库中。
取出第二行时,表头起作用。
homework.created_at 返回:2015-03-08 13:45:11 -0500
追踪:
app/views/homeworks/_homework.html.erb:6:in `_app_views_homeworks__homework_html_erb__2140072314140949314_70221661493300'
app/views/welcome/home.html.erb:26:in `block in _app_views_welcome_home_html_erb__3498543795407979710_70221651392200'
app/views/welcome/home.html.erb:24:in `_app_views_welcome_home_html_erb__3498543795407979710_70221651392200'
app/controllers/welcome_controller.rb:7:in `index'
homework.created_at.to_time 错误:undefined methodto_time' for nil:NilClass`
【问题讨论】:
-
能否提供完整的回溯?
-
@maxd 添加和更新!
-
这只是回溯的一部分。有错误的 HTML 页面应该有链接
Full Trace。单击它,您将看到完整的回溯。 -
在任何情况下都尝试在没有
time_ago_in_words帮助器的情况下输出homework.created_at。它不应该是零。检查一下。
标签: ruby-on-rails ruby ruby-on-rails-4 erb