TechpitのTrello風ToDoタスク管理アプリを作成しよう!【Rails】学習中、Herokuへのデプロイ後にアクセスしても、アプリが開けなかった。
その際の対処法メモ。
エラー内容の確認

Herokuにアクセスしすると、こんなエラー画面が出てくる。
言われた通り、入力してみる。
$ heroku logs --tail
すると、こんなエラーメッセージが出てきた。
2020-08-16T07:23:44.965520+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=desolate-oasis-68193.herokuapp.com request_id=xxxxxxxxxxxxxxxxxx fwd="xxx.xx.xxx.xxx" dyno= connect= service= status=503 bytes= protocol=https
2020-08-16T07:23:45.999074+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=desolate-oasis-68193.herokuapp.com request_id=xxxxxxxxxxxxxxxxxx fwd="xxx.xx.xxx.xxx" dyno= connect= service= status=503 bytes= protocol=https
H10 App crashed
H10のエラーとはこんな意味。
H10 – App crashed
A crashed web dyno or a boot timeout on the web dyno will present this error.
Heroku Error Codes https://devcenter.heroku.com/articles/error-codes#h10-app-crashed

分からんわww
しかも、対処法書いてないし!
参考記事

エラーの内容(H10)は全く同じ。しかし、エラーメッセージが違うので対処法は異なる。
仮説1:前に使用したときに、無茶したか?Herokuでの問題の可能性がある?
仮説
まだHerokuに慣れていない自分は、前に使用した時に無茶をしてしまったか?
その影響を引きずっているのか?
検証/対策
$ heroku destroy [app name]
にて前に作成したゴミアプリと現アプリを削除し、再度 heroku createしてみた。
結果
エラーメッセージ増えた(笑)
なんでやねんww
仮説2:データベースが怪しい
仮説
作成したデータベースは、sqlite3。
ただし、Heroku用ではPostgresqlなので、そこの連携がうまくいってないのかもしれない。
検証/対策
ポスグレ入ってるはずだけど、もう一回やってみっか…。
$ brew install postgresql
Error: postgresql 12.3_4 is already installed
To upgrade to 12.4, run `brew upgrade postgresql`.
案の定入っていたけど、最新版ではなかったらしい。とりあえず、最新版にしとく。
$brew upgrade postgresql
結果
効果なし。
仮説3:データベースではない…?
仮説
よくログを見てみると、他にも下記のメッセージが出ていました。
remote: -----> Detecting rails configuration
remote:
remote: ###### WARNING:
remote:
remote: Detecting rails configuration failed
remote: set HEROKU_DEBUG_RAILS_RUNNER=1 to debug
remote:
remote: ###### WARNING:
remote:
remote: We detected that some binary dependencies required to
remote: use all the preview features of Active Storage are not
remote: present on this system.
remote:
remote: For more information please see:
remote: https://devcenter.heroku.com/articles/active-storage-on-heroku
remote:
remote:
remote: ###### WARNING:
remote:
remote: There is a more recent Ruby version available for you to use:
remote:
remote: 2.6.6
remote:
remote: The latest version will include security and bug fixes. We always recommend
remote: running the latest version of your minor release.
remote:
remote: Please upgrade your Ruby version.
remote:
remote: For all available Ruby versions see:
remote: https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
remote:
remote: ###### WARNING:
remote:
remote: No Procfile detected, using the default web server.
remote: We recommend explicitly declaring how to boot your server process via a Procfile.
remote: https://devcenter.heroku.com/articles/ruby-default-web-server
検証/対策
とりあえず、一つひとつ、エラー解決していきますか。
Warning 1:Detecting rails configuration failed
$ set HEROKU_DEBUG_RAILS_RUNNER=1 to debug
Warning 3:Rubyの更新
Rubyを2.6.6に更新。
Warning 1と4…

1番上と3番目は解決できたけど、2番目のbinary dependenciesと4番目のProcfileってなんぞや…。
とりあえず、これだけでいっかw
結果
変化なし…。
仮説4:やっぱデータベースやろ!
仮説
いやいやいや、やっぱりデータベースでしょ!
remote: Verifying deploy... done.
とログに出てきているから、デプロイはできてるっていうことだもんな!
検証/対策

上記記事に従って、Config → database.yml 確認。
productionのところがSqlite3になってる!!これだ!!
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
# adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
adapter: sqlite3
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
adapter: postgresql #変更
database: db/production.pg
結果
変わらんのかーーーいwww
うまくいくと思ったんだけどなぁ…
仮説5:もう分からん。
仮説
もう色々やった。何が原因か分からない。
Herokuのコンソールみる方法があると見つけ、やってみた。
$ heroku run console
検証/対策
そしたら、なんとエラーメッセージの出現!
1: from /app/app/controllers/users/registrations_controller.rb:3:in `<main>'
/app/app/controllers/users/registrations_controller.rb:17:in `<class:RegistrationsController>': undefined method `GET' for Users::RegistrationsController:Class (NoMethodError)
Did you mean? gets
gem
自分はこのエラーメッセージを知っている!よくみるぞ!
とりあえず、Registrations_controllerの17行目を見ればいいんだな!
users/registrations_controller.rb
# GET /resource/edit このコメントアウトが外れていた
def edit
@user = User.find(params[:id])
end
# PUT /resource このコメントアウトが外れていた
def update
@user = User.find(params[:id])
@user.update
end
deviceで作成したコントローラのコメントアウトが外れていました。
外れた状態でも、ローカル環境では動くんですなぁ。
再度コメントアウトしました。
結果

成功〜〜〜〜〜!
結論
一番初めに紹介した記事でもHerokuのコンソールをみて解決してたんですよね。
とりあえず、herokuのコンソールやってみましょう!
感想
ここの記事で書いた以上のことを色々と試してみました。
解決まで2日かかかりましたが、原因は些細なことであることはよくある話ですね。。。
参考記事



コメント