英雄500错误但不在本地

时间:2016-11-28 22:26:59

标签: ruby-on-rails heroku

我正在部署英雄并且它很成功但是当我去英雄网址时我得到了500错误。这是我的日志文件



2016-11-28T22:19:09.106733+00:00 app[web.1]:     10:     <tbody>
2016-11-28T22:19:09.106735+00:00 app[web.1]:     11:     <% @users.try(:each) do |user| %>
2016-11-28T22:19:09.106736+00:00 app[web.1]:     13:           <td><%= user.first_name + " " + user.last_name %></td>
2016-11-28T22:19:09.106735+00:00 app[web.1]:     12:         <tr>
2016-11-28T22:19:09.106737+00:00 app[web.1]:     14:           <td><%= user.email %></td>
2016-11-28T22:19:09.106737+00:00 app[web.1]:     15:           <td>
2016-11-28T22:19:09.106738+00:00 app[web.1]:     16:             <% if follow = user.follows.find_by(follows: user.id) %>
2016-11-28T22:19:09.106742+00:00 app[web.1]:   app/views/follows/index.html.erb:11:in `_app_views_follows_index_html_erb___1812592661839220487_70215972087760'
2016-11-28T22:19:09.106741+00:00 app[web.1]:   app/views/follows/index.html.erb:13:in `block in _app_views_follows_index_html_erb___1812592661839220487_70215972087760'
2016-11-28T22:19:09.106742+00:00 app[web.1]: 
2016-11-28T22:19:09.106743+00:00 app[web.1]: 
2016-11-28T22:24:13.636808+00:00 heroku[router]: at=info method=GET path="/follows" host=sn-sql.herokuapp.com request_id=fb1f9eee-890b-4227-8185-2ada91825cb6 fwd="141.225.80.1" dyno=web.1 connect=0ms service=30ms status=500 bytes=1759
2016-11-28T22:24:13.634688+00:00 app[web.1]: Started GET "/follows" for 141.225.80.1 at 2016-11-28 22:24:13 +0000
2016-11-28T22:24:13.637819+00:00 app[web.1]: Processing by FollowsController#index as HTML
2016-11-28T22:24:13.642862+00:00 app[web.1]:   [1m[36mUser Load (0.9ms)[0m  [1mSELECT "users".* FROM "users"[0m
2016-11-28T22:24:13.645429+00:00 app[web.1]:   Rendered follows/index.html.erb within layouts/application (4.4ms)
2016-11-28T22:24:13.645666+00:00 app[web.1]: Completed 500 Internal Server Error in 8ms (ActiveRecord: 0.9ms)
2016-11-28T22:24:13.647633+00:00 app[web.1]: 
2016-11-28T22:24:13.647634+00:00 app[web.1]: ActionView::Template::Error (undefined method `+' for nil:NilClass):
2016-11-28T22:24:13.647635+00:00 app[web.1]:     10:     <tbody>
2016-11-28T22:24:13.647636+00:00 app[web.1]:     11:     <% @users.try(:each) do |user| %>
2016-11-28T22:24:13.647637+00:00 app[web.1]:     12:         <tr>
2016-11-28T22:24:13.647637+00:00 app[web.1]:     13:           <td><%= user.first_name + " " + user.last_name %></td>
2016-11-28T22:24:13.647638+00:00 app[web.1]:     14:           <td><%= user.email %></td>
2016-11-28T22:24:13.647639+00:00 app[web.1]:     15:           <td>
2016-11-28T22:24:13.647639+00:00 app[web.1]:     16:             <% if follow = user.follows.find_by(follows: user.id) %>
2016-11-28T22:24:13.647640+00:00 app[web.1]:   app/views/follows/index.html.erb:13:in `block in _app_views_follows_index_html_erb___1812592661839220487_70215972087760'
2016-11-28T22:24:13.647641+00:00 app[web.1]:   app/views/follows/index.html.erb:11:in `_app_views_follows_index_html_erb___1812592661839220487_70215972087760'
2016-11-28T22:24:13.647642+00:00 app[web.1]: 
2016-11-28T22:24:13.647642+00:00 app[web.1]: 
2016-11-28T22:28:05.898802+00:00 app[web.1]: Started HEAD "/" for 54.80.172.253 at 2016-11-28 22:28:05 +0000
2016-11-28T22:28:05.900540+00:00 app[web.1]: Processing by NewsFeedController#index as HTML
2016-11-28T22:28:05.903485+00:00 app[web.1]:   Rendered posts/_form.html.erb (1.4ms)
2016-11-28T22:28:05.904672+00:00 app[web.1]:   [1m[35mPost Load (0.8ms)[0m  SELECT "posts".* FROM "posts"
2016-11-28T22:28:05.907075+00:00 app[web.1]:   [1m[36mUser Load (1.0ms)[0m  [1mSELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m  [["id", 1]]
2016-11-28T22:28:05.913989+00:00 app[web.1]:   Rendered posts/_post.html.erb (9.0ms)
2016-11-28T22:28:05.914213+00:00 app[web.1]:   Rendered news_feed/index.html.erb within layouts/application (12.3ms)
2016-11-28T22:28:05.914387+00:00 app[web.1]: Completed 500 Internal Server Error in 14ms (ActiveRecord: 1.8ms)
2016-11-28T22:28:05.915476+00:00 app[web.1]: 
2016-11-28T22:28:05.915478+00:00 app[web.1]: ActionView::Template::Error (undefined method `id' for nil:NilClass):
2016-11-28T22:28:05.915479+00:00 app[web.1]:     20:             </div>
2016-11-28T22:28:05.915480+00:00 app[web.1]:     21:             <div class="panel-body">
2016-11-28T22:28:05.915481+00:00 app[web.1]:     22:               <p><%= post.post_text %></p>
2016-11-28T22:28:05.915484+00:00 app[web.1]:     23:               <% if like = post.likes.find_by(user_id: current_user.id) %>
2016-11-28T22:28:05.915485+00:00 app[web.1]:     24:                   <%= link_to '<i class="fa fa-thumbs-down" aria-hidden="true"></i> Unlike'.html_safe, like, method: 'delete',class: ""  %>
2016-11-28T22:28:05.915486+00:00 app[web.1]:     25:               <% else %>
2016-11-28T22:28:05.915487+00:00 app[web.1]:     26:                   <%= link_to '<i class="fa fa-thumbs-up" aria-hidden="true"></i> Like'.html_safe, likes_path({post_id: post.id}), method: 'post',class: ""  %>
2016-11-28T22:28:05.915488+00:00 app[web.1]:   app/views/posts/_post.html.erb:23:in `_app_views_posts__post_html_erb__2305306643930163929_70215970144600'
2016-11-28T22:28:05.915489+00:00 app[web.1]:   app/views/news_feed/index.html.erb:3:in `block in _app_views_news_feed_index_html_erb__1204754539652968054_70215970424660'
2016-11-28T22:28:05.915490+00:00 app[web.1]:   app/views/news_feed/index.html.erb:2:in `_app_views_news_feed_index_html_erb__1204754539652968054_70215970424660'
2016-11-28T22:28:05.915491+00:00 app[web.1]: 
2016-11-28T22:28:05.915491+00:00 app[web.1]: 
2016-11-28T22:28:05.907994+00:00 heroku[router]: at=info method=HEAD path="/" host=sn-sql.herokuapp.com request_id=85b21e2a-cdc7-4bfe-a3b5-8ff1ca1a460e fwd="54.80.172.253" dyno=web.1 connect=0ms service=19ms status=500 bytes=277
&#13;
&#13;
&#13;

不知道发生了什么,因为它在我的本地服务器上完全正常工作。不确定日志中的任何含义。任何帮助都会很棒。

1 个答案:

答案 0 :(得分:0)

首先,您应该尝试习惯阅读日志,因为如果您开始开发rails应用程序,它是您需要擅长调试的主要内容之一。

他们的日志告诉你这里有什么错误

 ActionView::Template::Error (undefined method `+' for nil:NilClass):

基本上是说你试图将nil添加到某些内容中,这显然没有意义,因此错误。如果你看下面的块,你可以看到你试图在这里添加用户的名字和姓氏

<td><%= user.first_name + " " + user.last_name %></td>

因此该用户缺少名字或姓氏。所以你需要的只是一个条件,以确保在你添加它们之前存在它们,比如

<% if user.first_name && user.last_name %>
  <td><%= user.first_name + " " + user.last_name %></td>

  whatever else...
<% end %>

你还有另一个错误

ActionView::Template::Error (undefined method `id' for nil:NilClass):
告诉你类似的东西。尝试弄清楚错误来自哪里,因为正如我所说的,能够调试自己的代码对于开发至关重要,无论语言如何

相关问题