Steps to reproduce
- Gemfileのproductionに
gem "pg", "1.0.0"
を追記 - bundle install
- git add .
- git commit
- git push heroku master
- Webアプリのトップページを開く
Expected behavior
ちゃんとWebアプリが動く
Actual behavior
アプリが動かず、
2018-04-23T02:16:05.027483+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/"
のような、なぜかクラッシュしていることだけがわかるログが現れる。
How to do to resolve
まず、何が起こっているか確認したい。
なので以下の手順でログを確認する。
- heroku run rails c
- Webアプリにアクセス
(参考:http://www.workabroad.jp/posts/2166)
すると
`rescue in spec': Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
というように、postgresqlがうまく動いていないというエラーが見て取れる。
このエラーメッセージで検索すると、以下のページが見つかった。
https://github.com/rails/rails/issues/31673
回答にあったリンク先に向かうと、
https://github.com/rails/rails/issues/31669
とあり、現在のrailsではpostgresql 1.0.0はサポートされていないことがわかる。
なので、以下の手順で解決する。
- Gemfileのproductionのpgを
gem "pg", "~> 0.21.0"
に変更 - bundle install
- git add .
- git commit
- git push heroku master
- Webアプリのトップページを開く
無事に動きました。