加载没有本地主机:3000的问题,但一旦部署到Heroku我收到以下错误。 RanHeroku问题,ActionView :: Template :: Error(未定义的方法名称为nil:NilClass):
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个新的用户字段我的数据库,所有的字符串。 Ran
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>
上面更新的代码。 – cpflores
您已收到以下两个完整答案。如果您表示是否已经有效,这会很有帮助。 – zeantsoi