rails6 heroku デプロイ

Bundler2のインストール前に確認

そして、「vendor/bundle」以下にGemがインストールされるようにオプションをつけて、「bundle install」コマンドを実行します。

$ bundle install --path vendor/bundle

これによってRailsアプリケーションで扱うGemを、個々のアプリケーション別に分けて扱うことができます。

アプリを作成する時はこのようにGemをインストールすると、アプリごとでGemを自動で切り替えてくれるようになります。


bundler2へupgradeする

//rubyは2.3.0以上
% ruby -v
ruby 2.6.1p33

//gemは2.5.0以上
 % gem -v
3.0.1

//実行
bundle update --bundler

Using web-console 4.2.0
Bundle updated!

[Ruby] bundler 2 へのアップグレード方法 | DevelopersIO

bundle exec rake db:seed

bundle exec rake db:migrate

bundle exec rake db:migrate でエラー

//マイグレーションファイルの状態を確認 upになっていたら削除すると大変
bundle exec rake db:migrate:status

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20190204121722  Devise create users
   up     20190204125329  Create requests
   up     20190204125917  Create th words
   up     20190204125925  Create jp words
   up     20190204125930  Create en words
   up     20190204130000  Create sentences
   up     20190204130043  Create th word sentences
   up     20190204130935  Add column to user
   up     20190204131737  Add column to th word sentences
   up     20190501150418  Create downloads
   up     20190501151520  Add file
  down    20191020041100  Change stury to binary
  down    20201016045316  Change column to user

downになっているので削除

その後

bundle exec rake db:migrate

rails s でエラー

This model adapter does not support fetching records from the database.

調査するとcancan canのバージョンを3以上にしなさいと、、、

ruby on rails - This model adapter does not support fetching records from the database - Stack Overflow

本家サイト

cancancan | RubyGems.org | your community gem host

rails s で

OK f:id:happy_teeth_ago:20211213122314p:plain

まだまだこれから

Herokuへデプロイ時 エラー対応

まず mainブランチでないとだめになったようだmasterだったので、切り替える

git checkout -b main

Cloud9からだったので、環境変数を追加しなさい

bundle lock --add-platform x86_64-linux

エラー

! remote: ! Failed to install gems via Bundler. remote: ! Detected sqlite3 gem which is not supported on Heroku: remote: ! https://devcenter.heroku.com/articles/sqlite3

sqlite3のgemはそもそもdevelop環境にもインストールしてはいけない

SQLite on Heroku | Heroku Dev Center

https://devcenter.heroku.com/articles/sqlite3

herokuのポスグレのバージョン確認 11.14らしい

 heroku pg:info


Plan:                  Hobby-basic
Status:                Available
Connections:           2/20
PG Version:            11.14
Created:               2019-04-10 01:25 UTC
Data Size:             13.3 MB/10.00 GB (In compliance)
Tables:                9
Rows:                  38225/10000000 (In compliance)
Fork/Follow:           Unsupported
Rollback:              Unsupported
Continuous Protection: Off

MACにポスグレを入れる

Docker今からは面倒なのと、herokuにDockerpushしたことがないため

//インストール可能なバージョン確認
brew install postgresql

==> Formulae
postgresql ✔         postgresql@11        postgresql@13        postgresql@9.5       qt-postgresql
postgresql@10        postgresql@12        postgresql@9.4       postgresql@9.6       postgrest


//11があったのでインストール
brew install postgresql@11


//起動
 brew services restart postgresql@11

//DB作成
% bundle exec rake db:create

% bundle exec rake db:migrate
== 20190204121722 DeviseCreateUsers: migrating ================================
-- create_table(:users, {})
   -> 0.0190s

rails s 
起動する

データ投入

heroku run rake db:migrate

heroku run rake db:seed

localのポスグレの起動、終了、確認

 brew services stop postgresql@11