3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Ruby on Rails チュートリアル 第6版】環境周りでハマったことログ

Last updated at Posted at 2021-02-19

やりたいこと

Ruby on Rails 第6版を進めていて環境構築周りで詰まることが多かったので、ログとしてまとめます。
※随時更新予定

Cloud9環境

初めてAWSを利用したこともあり、些細なことでハマりました。

リージョンの設定

ログインして最初の設定では、「米国東部(バージニア北部」に設定されているため、「アジアパシフィック(東京)」を選択します。
最初はこの設定に気付かず「なんだかキーボード打っても反応が遅いなぁ」と思っていました。
image.png

EC2の設定

Cloud9の環境を作成すると、EC2のインスタンスが自動で作成されます。
ですが、このEC2インスタンスの容量が10GBしかなく、チュートリアルを進めていると No space left on device というエラーが発生します。
その場合は、AWS Cloud9 の容量不足を解決するを参照してEC2インスタンスのボリュームを増加させます。

別インスタンスでデプロイする

別リージョンでCloud9の環境を作成した際には、以下の流れでソースを取得して rails server の実行まで行うことができます。

$ git clone https://github.com/<user_name>/hello_app.git // GitHubのソースコードをクローン
$ cd hello_app                                           // Railsのフォルダへ移動
$ bundle install --without production                    // Production 環境以外の Bundle install を実行
$ npm install --global yarn                              // npm でグローバル環境に yarn コマンドをインストール
$ yarn install --check-files                             // yarn をインストール
$ rails server                                           // 開発用サーバーを起動

rails server を実行する際には yarn のインストールが必須のためCloud9にインストールされている npm 経由でインストールをしています。

Herokuへのデプロイ

Stackの変更

Stackを切り替えるのは本来好ましくないため、Stackの変更は行いません。
heroku-20では、チュートリアルで利用している Ruby 2.6.3 が利用できないエラーが発生します。
heroku-18であれば、チュートリアルで利用しているバージョンのRubyが利用できるので、 heroku create 後に以下のコマンドを実行してStackを切り替えます。

Gemfileの編集

heroku create で自動的に作成される環境はheroku-20のStackが利用されており、以下のようなRuby 2.6.3 が利用できないエラーが発生します。

Rubyバージョンエラーログ
remote:  !     The Ruby version you are trying to install does not exist on this stack.
remote:  !     
remote:  !     You are trying to install ruby-2.6.3 on heroku-20.
remote:  !     
remote:  !     Ruby ruby-2.6.3 is present on the following stacks:
remote:  !     
remote:  !     - cedar-14
remote:  !     - heroku-16
remote:  !     - heroku-18
remote:  !     
remote:  !     Heroku recommends you use the latest supported Ruby version listed here:
remote:  !     https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
remote:  !     
remote:  !     For more information on syntax for declaring a Ruby version see:
remote:  !     https://devcenter.heroku.com/articles/ruby-versions
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.

こちらのエラーは、Gemfileにて明示的にRubyバージョンが指定されているため発生しています。
以下の手順で対応することで上記エラーへ対処可能です。

  1. Gemfileの ruby '2.6.3' となっている行を削除して上書き
  2. bundle install --without production を実行
  3. git commit で変更点をGitHubにコミット
  4. git push heroku master でHerokuへデプロイ

Heroku Appの紐づけ変更

チュートリアル用のプロジェクト内でheroku createで作成したHeroku Appを削除したのち、git push heroku masterを行うと! No app specified.というエラーが発生します。
これはPush先のAppが無いですよというエラーなので、デプロイ先のAppを以下のように明示的に指定すれば解決します。

$ heroku git:remote --app app_name

app_nameの箇所に自身のHeroku AppのApp名を入れ、コマンドを実行してください。

また、自身がいるProjectがどのHeroku Appに紐づいているかはheroku infoで確認することができます。

Heroku App 割り当て前

$ heroku info
 ▸    No app specified.
 ▸    USAGE: heroku info my-app

Heroku App 割り当て後

$ heroku info
=== app_name
app_nameの情報....

Railsのコマンド

rails consoleが起動しない

Yarn のエラーによりrails consoleコマンドが起動しないエラーが発生しました。

$ rails console --sandbox
warning Integrity check: System parameters don't match                                                             
error Integrity check failed                                                                                       
error Found 1 errors.                                                                                              


========================================
  Your Yarn packages are out of date!
  Please run `yarn install --check-files` to update.
========================================


To disable this check, please change `check_yarn_integrity`
to `false` in your webpacker config file (config/webpacker.yml).


yarn check v1.22.10
info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.

※エラーに記載されている通りyarn install --check-filesを実行しても、同一のエラーが発生します

node_moduleのディレクトリ、yarn.lockを削除しyarn installする方法も実行しましたが、私の環境では動作せず。。。
最終的に以下の方法で起動するようになりました。

$ spring stop   // springを止める
$ spring status // springは自動的に再起動するので、起動しているかをチェック
3
1
2

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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?