herokuへのデプロイをしてブラウザに「We're sorry, but something went wrong.」が表示されたので、「heroku run rails db:migrate」を実行しエラーを解消しようとしましたが、何も変化はないです。railsで実装したサイトをheroku上に表示させたいです。
「heroku logs --tail」を実行し、ログの中にエラー原因がないか探ってみましたが、まだ読み方がわからないので特定できない状態です。
どなたかご教授いただければ幸いです。よろしくお願いします。
% heroku logs --tail # 省略(下の方の最新情報だけにしました。) 2021-01-26T09:27:14.130369+00:00 heroku[router]: at=info method=GET path="/" host=blooming-earth-90741.herokuapp.com request_id=ca22c9ef-5841-4406-8935-b42c3cd97718 fwd="60.151.23.213" dyno=web.1 connect=1ms service=151ms status=500 bytes=1827 protocol=https 2021-01-26T09:30:21.913263+00:00 app[api]: Starting process with command `rails db:migrate` by user ryun19901208hk@yahoo.co.jp 2021-01-26T09:30:30.512477+00:00 heroku[run.6124]: State changed from starting to up 2021-01-26T09:30:30.989902+00:00 heroku[run.6124]: Awaiting client 2021-01-26T09:30:31.020719+00:00 heroku[run.6124]: Starting process with command `rails db:migrate` 2021-01-26T09:30:45.857557+00:00 heroku[run.6124]: Process exited with status 0 2021-01-26T09:30:45.897420+00:00 heroku[run.6124]: State changed from up to complete 2021-01-26T09:30:55.413674+00:00 app[web.1]: I, [2021-01-26T09:30:55.413546 #4] INFO -- : [a248307a-8fe9-4521-ad33-8a5c7e05c012] Started GET "/" for 60.151.23.213 at 2021-01-26 09:30:55 +0000 2021-01-26T09:30:55.414683+00:00 app[web.1]: I, [2021-01-26T09:30:55.414612 #4] INFO -- : [a248307a-8fe9-4521-ad33-8a5c7e05c012] Processing by NewsController#index as HTML 2021-01-26T09:30:55.483201+00:00 app[web.1]: I, [2021-01-26T09:30:55.483051 #4] INFO -- : [a248307a-8fe9-4521-ad33-8a5c7e05c012] Rendering news/index.html.erb within layouts/application 2021-01-26T09:30:55.485005+00:00 app[web.1]: I, [2021-01-26T09:30:55.484910 #4] INFO -- : [a248307a-8fe9-4521-ad33-8a5c7e05c012] Rendered news/index.html.erb within layouts/application (Duration: 1.6ms | Allocations: 496) 2021-01-26T09:30:55.485231+00:00 app[web.1]: I, [2021-01-26T09:30:55.485149 #4] INFO -- : [a248307a-8fe9-4521-ad33-8a5c7e05c012] Completed 500 Internal Server Error in 70ms (Allocations: 1425) 2021-01-26T09:30:55.491118+00:00 app[web.1]: F, [2021-01-26T09:30:55.490988 #4] FATAL -- : [a248307a-8fe9-4521-ad33-8a5c7e05c012] 2021-01-26T09:30:55.491120+00:00 app[web.1]: [a248307a-8fe9-4521-ad33-8a5c7e05c012] ActionView::Template::Error (undefined method `each' for nil:NilClass): 2021-01-26T09:30:55.491120+00:00 app[web.1]: [a248307a-8fe9-4521-ad33-8a5c7e05c012] 5: <p class="font">Powered by <a href="https://newsapi.org", class="btn">News API</a></p> 2021-01-26T09:30:55.491122+00:00 app[web.1]: [a248307a-8fe9-4521-ad33-8a5c7e05c012] 6: </header> 2021-01-26T09:30:55.491122+00:00 app[web.1]: [a248307a-8fe9-4521-ad33-8a5c7e05c012] 7: <div class="articles"> 2021-01-26T09:30:55.491123+00:00 app[web.1]: [a248307a-8fe9-4521-ad33-8a5c7e05c012] 8: <% @articles["articles"].each do |article| %> 2021-01-26T09:30:55.491123+00:00 app[web.1]: [a248307a-8fe9-4521-ad33-8a5c7e05c012] 9: <div class="article"> 2021-01-26T09:30:55.491124+00:00 app[web.1]: [a248307a-8fe9-4521-ad33-8a5c7e05c012] 10: <div class="title"> 2021-01-26T09:30:55.491124+00:00 app[web.1]: [a248307a-8fe9-4521-ad33-8a5c7e05c012] 11: <%= link_to article["title"], article["url"] %> 2021-01-26T09:30:55.491125+00:00 app[web.1]: [a248307a-8fe9-4521-ad33-8a5c7e05c012] 2021-01-26T09:30:55.491125+00:00 app[web.1]: [a248307a-8fe9-4521-ad33-8a5c7e05c012] app/views/news/index.html.erb:8 2021-01-26T09:30:55.497168+00:00 heroku[router]: at=info method=GET path="/" host=blooming-earth-90741.herokuapp.com request_id=a248307a-8fe9-4521-ad33-8a5c7e05c012 fwd="60.151.23.213" dyno=web.1 connect=6ms service=90ms status=500 bytes=1827 protocol=https
試したこと
下記URLの例を参考にしてみました。
【初心者向け】railsアプリをherokuを使って確実にデプロイする方法【決定版】
https://qiita.com/kazukimatsumoto/items/a0daa7281a3948701c39
Heroku500内部サーバーエラー
https://stackoverflow.com/questions/9017668/heroku-500-internal-server-error
VSコード
app/controllers/news_controller.rb class NewsController < ApplicationController require "open-uri" def index news_api_key = ENV["NEWS_API_KEY"] uri = URI.parse("http://newsapi.org/v2/top-headlines?country=jp&apiKey=#{news_api_key}") json = Net::HTTP.get(uri) @articles = JSON.parse(json) end end
app/vews/news/index.html.erb <main class="main"> <div class="inner"> </div> <header> <p class="font">Powered by <a href="https://newsapi.org", class="btn">News API</a></p> </header> <div class="articles"> <% @articles["articles"].each do |article| %> <div class="article"> <div class="title"> <%= link_to article["title"], article["url"] %> </div> <div class="wrapper"> <div class="date"> <%= article["publishedAt"] %> </div> <div class="source"> <%= article["source"]["name"]%> </div> <div class="image"> <%= image_tag article["urlToImage"] || 'hc-web-2018-news-1-sml-card.jpg.jpg', :size =>'240x160' %> </div> <div class="content"> <%= article["description"] %> </div > </div> </div> <% end %> </div> </main>
回答1件
あなたの回答
tips
プレビュー