LoginSignup
8
5

More than 3 years have passed since last update.

Railsチュートリアルで出会ったエラーとその対処法まとめ

Last updated at Posted at 2017-12-29

私がRailsチュートリアルを進める中で出会ったエラーとその対処法についてまとめていきます。(随時更新していきます。)

rails generateに失敗する

エラー内容

/usr/local/rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/configuration.rb:37:in `pwd':
 No such file or directory - getcwd (Errno::ENOENT)

原因

バックグラウンドでRails Springプロセスが起動しているため。

対処法

springプロセスを終了させれば解消されます。

  1. 以下のコマンドを実行してspringプロセスのプロセスIDを確認
    ps ax | grep spring

  2. 以下のコマンドを実行してspringプロセスを終了
    kill <手順1で確認したspringプロセスのプロセスID>

herokuのデプロイ時にWARNINGログが出力される

原因は2つありました。ビルド自体は成功します。

エラー内容 その1

###### WARNING:
       You have not declared a Ruby version in your Gemfile.
       To set your Ruby version add this line to your Gemfile:
       ruby '2.3.4'
       # See https://devcenter.heroku.com/articles/ruby-versions for more information.

原因

GemfileにRubyのバージョン書いていなかったため。

対処法

以下の手順でGemfileにRubyのバージョンを追記
1.開発環境で使用しているRubyのバージョンを以下のコマンドで確認
ruby --version
2.Gemfileに追記
ruby '<手順1で確認したバージョン番号>'
3.herokuにデプロイ

エラー内容 その2

###### WARNING:
       No Procfile detected, using the default web server.
       We recommend explicitly declaring how to boot your server process via a Procfile.
       https://devcenter.heroku.com/articles/ruby-default-web-server

原因

Procfileに指定しない限り、デフォルトで使用されるWebサーバーがWEBrickになる。WEBrickはシングルプロセス、シングルスレッドであるため、複数のリクエストを一括処理することができない。

対処法

複数命令を並行して処理できるPumaを使用することが推奨されている。Pumaを使用するにはProcfileの作成とConfig(puma.rb)ファイルの作成が必要
1.アプリケーションのルートディレクトリに「Procfile」ファイルを作成し、以下のように追記

web: bundle exec puma -C config/puma.rb

2.configディレクトリに「puma.rb」ファイルを作成し、以下のように追記

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
end
8
5
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
8
5