2016-11-28 55 views
0

我部署到英雄,它是成功的,但當我去了英雄的URL我得到了500錯誤。這裏是我的日誌文件英雄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

不知道是怎麼回事,因爲它的工作我的本地服務器上完全沒問題。不知道這在日誌中有什麼含義。任何幫助都會很棒。

回答

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): 

另一個錯誤,告訴你類似的東西。試着找出錯誤來自哪裏,正如我所說的,能夠調試自己的代碼對於開發是必不可少的,無論語言如何,