0

在开发中它工作得很好,但在生产(Heroku)上,它因以下错误而中断。

错误实际上在

<%= link_to clip.user.show.name, clip.user.show %>

错误日志:

ActionView::Template::Error (undefined method `name' for nil:NilClass):
2013-09-02T10:24:09.366120+00:00 app[web.1]:     34:
2013-09-02T10:24:09.366120+00:00 app[web.1]:     35:   <p class="clip-uploader pull-left" data-no-turbolink>
2013-09-02T10:24:09.366120+00:00 app[web.1]:     36:     <strong>
2013-09-02T10:24:09.366120+00:00 app[web.1]:     37:       <%= link_to clip.user.show.name, clip.user.show %>
2013-09-02T10:24:09.366120+00:00 app[web.1]:     38:     </strong>
2013-09-02T10:24:09.366120+00:00 app[web.1]:     39:   </p>
2013-09-02T10:24:09.366120+00:00 app[web.1]:     40:
2013-09-02T10:24:09.366120+00:00 app[web.1]:   app/views/clips/_clip.html.erb:37:in `_app_views_clips__clip_html_erb_

为什么这会在 heroku 上刹车?

4

2 回答 2

2

The Solution was that i had 1 pre existing Clip in my Database from a very early version that had no show attached.

于 2013-09-02T11:16:35.660 回答
1

它清楚地提到clip.user.show 不是零,这意味着clip.user 在数据库中不存在。如果某些值可以为零,则可以尝试以下操作:-

<%if clip.user.show.present?%>
<%= link_to clip.user.show.name, clip.user.show %>
<%end%>
于 2013-09-02T10:46:25.807 回答