在 localhost:3000 上加载没有问题,但是一旦部署到 Heroku,我就会收到以下错误。冉
heroku logs --tail
2013-08-29T04:38:23.403690+00:00 app[web.1]: Connecting to database specified by DATABASE_URL
2013-08-29T04:38:26.898295+00:00 app[web.1]: [2013-08-29 04:38:26] INFO WEBrick 1.3.1
2013-08-29T04:38:26.898295+00:00 app[web.1]: [2013-08-29 04:38:26] INFO ruby 2.0.0 (2013-06-27) [x86_64-linux]
2013-08-29T04:38:26.898634+00:00 app[web.1]: [2013-08-29 04:38:26] INFO WEBrick::HTTPServer#start: pid=2 port=11226
2013-08-29T04:38:27.010520+00:00 heroku[web.1]: State changed from starting to up
2013-08-29T04:38:28.496863+00:00 app[web.1]: Started GET "/" for 50.148.15.124 at 2013-08-29 04:38:28 +0000
2013-08-29T04:38:28.642277+00:00 app[web.1]: Processing by EventsController#index as HTML
2013-08-29T04:38:29.529140+00:00 heroku[router]: at=info method=GET path=/ host=afternoon-gorge-1648.herokuapp.com fwd="50.148.15.124" dyno=web.1 connect=5ms service=1081ms status=500 bytes=643
2013-08-29T04:38:29.541662+00:00 app[web.1]: Rendered events/_event.html.erb (320.3ms)
2013-08-29T04:38:29.541795+00:00 app[web.1]: Rendered events/index.html.erb within layouts/application (743.9ms)
2013-08-29T04:38:29.542093+00:00 app[web.1]: Completed 500 Internal Server Error in 900ms
2013-08-29T04:38:29.544607+00:00 app[web.1]:
2013-08-29T04:38:29.544607+00:00 app[web.1]: ActionView::Template::Error (undefined method `name' for nil:NilClass):
2013-08-29T04:38:29.544607+00:00 app[web.1]: 3: <td><%= event.title %></td>
2013-08-29T04:38:29.544607+00:00 app[web.1]: 4: <td><%= event.location %></td>
2013-08-29T04:38:29.544607+00:00 app[web.1]: 5: <td><%= event.description %></td>
2013-08-29T04:38:29.544607+00:00 app[web.1]: 6: <td><strong><%= link_to event.user.name, event.user %></strong></td>
2013-08-29T04:38:29.544607+00:00 app[web.1]: 7: <td><%= link_to 'Show', event %></td>
2013-08-29T04:38:29.544607+00:00 app[web.1]: 8: <% if current_user == event.user %>
2013-08-29T04:38:29.544607+00:00 app[web.1]: 9: <td><%= link_to 'Edit', edit_event_path(event) %></td>
2013-08-29T04:38:29.544607+00:00 app[web.1]: app/views/events/_event.html.erb:6:in `_app_views_events__event_html_erb___4373324357052961172_69914882818260'
2013-08-29T04:38:29.544790+00:00 app[web.1]: app/views/events/index.html.erb:20:in `_app_views_events_index_html_erb___3028579038251132182_69914889655380'
2013-08-29T04:38:29.544790+00:00 app[web.1]: app/controllers/events_controller.rb:9:in `index'
我已经确认我的数据库在本地和 Heroku 上匹配。该应用程序仅在登录时失败。登录页面在注销时加载正常。当我在我的数据库中添加新的 7 个新用户字段时发生这种情况,所有字符串。冉
rake db:migrate
本地。
冉
heroku run rake db:migrate.
这是 Heroku 链接: http ://afternoon-gorge-1648.herokuapp.com/
非常困惑问题出在哪里。
更新:这是事件索引页面:
<% if user_signed_in? %>
<div class="hero-unit">
<h1>Sign up for any of the following events!</h1>
</div>
<h1>Listing events</h1>
<table class="table table-striped">
<thead>
<tr>
<th>Image</th>
<th>Title</th>
<th>Location</th>
<th>Description</th>
<th>Posted by</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<%= render @events %>
</tbody>
</table>
<br/>
<%= link_to 'Add New Event', new_event_path, class: "btn btn-primary btn-large" %>
<% else %>
<%= render 'pages/home' %>
<% end %>
调用 _event.html.erb 部分:
<tr>
<td><%= image_tag event.image(:medium) %></td>
<td><%= event.title %></td>
<td><%= event.location %></td>
<td><%= event.description %></td>
<td><strong><%= link_to event.user.name, event.user %></strong></td>
<td><small><%= link_to 'Show', event %></small></td>
<% if current_user == event.user %>
<td><small><%= link_to 'Edit', edit_event_path(event) %></small></td>
<td><small><%= link_to 'Delete', event, method: :delete, data: { confirm: 'Are you sure?' } %></small></td>
<% end %>
</tr>