概要
https://railstutorial.jp/chapters/beginning?version=4.2
Railsのチュートリアルの「1.5 デプロイする」で嵌まりまくった。
以下解決までの手順をまとめます。
環境
ubuntu 16.04
$ ruby -v
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
$ rails -v
rails 4.2.2
$ gem -v
2.5.1
解決までの手順
herokuにデプロイした後ブラウザで該当のページを開くと以下のようなエラー
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
エラーログを見る
ここからチュートリアルの内容から離れていきます
$ heroku run rails console
...
heroku rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile
...
config/database.ymlの設定がsqlite3のままになっていたので修正
database.yml
production:
<<: *default
adapter: postgresql
database: db/production.pg
再度アップロードするも別のエラー
We're sorry, but something went wrong.
herokuにPostgreSQLを導入し、データベースを作りなおす必要がありました。
$ heroku addons:create heroku-postgresql:hobby-dev
$ heroku run rake db:migrate
Running rake db:migrate on stormy-chamber-94768... up, run.2136 (Free)
(15.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL)
(12.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migration
hello, world
人類の勝利。