LoginSignup
2
2

More than 5 years have passed since last update.

railsチュートリアル1章 herokuへのデプロイに七転八倒。

Last updated at Posted at 2019-04-03

railsチュートリアル1章後半のherokuへのデプロイにつまづきまくったので、2度とここでつまづかないようにまとめておきます。

railsチュートリアル1.5で

git push heroku master

を実行した後に生成されたアドレスをブラウザで開こうとしたら、
Application Errorの文字が、、、

下に書いてある
heroku logs --tail
を実行しても、

2019-04-02T08:45:11.178789+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=cherry-pudding-18708.herokuapp.com request_id=418c602d-6211-4552-9488-abbfd39fae16 fwd="115.69.237.151" dyno= connect= service= status=503 bytes= protocol=https
2019-04-02T08:45:11.634170+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=cherry-pudding-18708.herokuapp.com request_id=7d395db1-345a-40ad-833c-8e770f0b8b7b fwd="115.69.237.151" dyno= connect= service= status=503 bytes= protocol=https
^C

何言ってるか分かりません。笑

ここで
heroku run rails console
を実行。

`Add `gem 'sqlite3'`to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

の文字が。

railsチュートリアルのいうことを正確に聞いてきた人には分かりますが、sqlite3はGemfileで実行してますよ!?!?

ここで、またググる。

すると、ここの記事に答えに繋がりそうなことが、、、!
Rails Tutorial

原因

.bundle/config の中身が
BUNDLE_WITHOUT: "production"
になっていることが原因らしい。

あと、database.ymlも変更する必要があるっぽい。


対策

.bundle/configってどこにあるんだと思って探したけど、どこにも見つからなかったので、c9コマンドでそこまで移動。
BUNDLE_WITHOUT: "production"

#BUNDLE_WITHOUT: "production"
に変更。

それでもうまくいかない。
そこで、

datebase.ytml
production:
  <<: *default
  adapter: postgresql
  database: db/production.pg

に変更。

それでもうまくいかない、、、。

一旦、もう一度heroku run rails consoleをしてみると、

Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

あれ? Add gem 'pg'に変わってる!!
これを解決すれば、デプロイできるぞ、、、と思い、ググるが、答えが見つからない。
そこで、色々いじった後に git push heroku masterを実行してないことに気づき、実行。

これでデプロイが完了した。2日間格闘した甲斐があった。(おそらく、ここまで分からなかったら飛ばして次に行くほうが効率がいい)


まとめ

おそらく、database.ymlの変更が解決法に繋がったと考える。
それと、heroku run rails consoleで確認をすると丁寧にどこが間違っていたのかを教えてくれるので、有効活用していきたい。


2
2
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
2
2