LoginSignup
0
0

More than 1 year has passed since last update.

【Ruby on Rails Tutorial】HerokuにデプロイしたらApplication error[H10 (App crashed)]が発生したときの対処法

Posted at

はじめに

Ruby on Rails チュートリアルに沿って学習を進めていました。
エラーが発生した際の対処方法をメモしておく。

環境

Cloud9
Ruby 2.6.3
Rails 6.0.3

現象

1.5.2にて、HerokuへRailsアプリケーションをデプロイしてページを開こうとすると、エラー画面が表示された。
image.png

結論

database.ymlを下記のように書き換えた

config/database.yml
# SQLite. Versions 3.8.0 and up are supported.
#   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
  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.postgresql #修正後
  # database: db/production.sqlite3 #修正前

解決までの流れ

ログを確認する

エラー画面にログを見ろと書かれていたので、確認してみることに。

$ heroku logs -t

結果はこちら

・・・
2021-06-04T19:28:08.413724+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=infinite-earth-10732.herokuapp.com request_id=07713d54-3627-4199-8471-a0611bacfb48 fwd="36.2.154.134" dyno= connect= service= status=503 bytes= protocol=https
2021-06-04T19:28:08.683679+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=infinite-earth-10732.herokuapp.com request_id=ae2b39f4-9b4d-44c3-a769-3b37dd15dc51 fwd="36.2.154.134" dyno= connect= service= status=503 bytes= protocol=https

error code=H10, App crashedと言われた。
よくわからないのでググってみると、エラーの詳細内容を確かめるためにHeroku上でコンソールを開くことが出来るとのこと。
これも試してみます。

$ heroku run rails c

結果はこちら

・・・
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem': 
Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? sqlite3 is not part of the bundle. Add it to your Gemfile. (LoadError)

どうやらsqlite3まわりが原因のようだ。
引き続きネットで情報を検索すると、以下の情報を発見。

https://tex2e.github.io/blog/ruby/rails-on-heroku

これやん!!!ってことで、database.ymlを修正しました。

原因

Ruby on Rails チュートリアルでは、Herokuで使うデータベースとの競合を防ぐため、
production環境では、sqlite3ではなく、PostgreSQLを使用する。
Gemfileではそのように指定したが、database.ymlではsplite3を使用するようになっていた。
その不一致が原因ではないかと考えています。
(詳細はチュートリアルの1.3.1や1.5.1を参考に)

どこかでチュートリアルの手順を間違えてしまっていたのかもしれませんが、
無事エラーが解決されて満足です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0