Rails生成错误ActiveRecord :: RecordNotFound(无法找到没有ID的人)

时间:2013-12-15 20:47:42

标签: ruby-on-rails production-environment

我在Rails生产环境中只有很奇怪的错误。在开发中运作良好。日志在我的index.html.erb文件中显示此行中的错误。

这是生产日志错误:

ActiveRecord::RecordNotFound (Couldn't find Person without an ID):
  app/views/seeds/index.html.erb:71:in `block in _app_views_seeds_index_html_erb__4016841983995682700_31529840'
  app/views/seeds/index.html.erb:61:in `each'
  app/views/seeds/index.html.erb:61:in `_app_views_seeds_index_html_erb__4016841983995682700_31529840'
  app/controllers/seeds_controller.rb:17:in `index'

种子索引文件中的行是这一行:

<td><%= Person.find(seed.person_id).name %></td>

在此行之前,我使用外键以相同的方式查询其他数据并且它可以正常工作。当我检查sql表时,我看到Seeds表有person_id值。

此外,当我在生产环境中通过rails控制台查询相同的内容时,我会毫无问题地收到结果。但是,当我加载页面时,它显示“您正在寻找的页面不存在。”并且production.log显示上面的错误......任何想法可能出错?

1 个答案:

答案 0 :(得分:0)

对不起,经过一整天大脑编码的家伙并不好。关键是在表的中间我有一个人的NULL对象,这导致错误...谢谢你的时间