環境
- ruby: 2.4.3
- Rails: 5.1.2
- spring 2.0.2
原因
このissueにも挙がっていますが、一度アプリケーションを削除して同じ名前で rails new
しなおすと後述のエラーが出てハングアップするようです。
何が起きたか
rails tutorialを進める中で、ディレクトリ内でアプリケーション(appなど)を一度削除した後、もう一度同じ名前で rails new
して作り直しました。
その後、rails generate
しようとしたら時間がかかるなと思ったら、途中でハングアップしていました。
Ctrl+C
で中止すると下記のようなエラーが出ました。
$ rails g controller StaticPages home help about
Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/run.rb:117:in `gets': Interrupt
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/run.rb:117:in `verify_server_version'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/run.rb:62:in `run'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/run.rb:42:in `warm_run'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/run.rb:35:in `call'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:24:in `call'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/200491/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/200491/dev/go/src/momo-rails-tutorial/bin/spring:15:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
springというライブラリでエラーが出ている様子。
このissueに挙がっていました。
https://github.com/rails/spring/issues/265
対処法
issueの中にあったとおり、一旦springを停止して再度実行します。
$ spring stop
Spring stopped.
$ rails generate controller StaticPages home help about
Running via Spring preloader in process 56642
create app/controllers/static_pages_controller.rb
route get 'static_pages/help'
route get 'static_pages/home'
invoke erb
create app/views/static_pages
create app/views/static_pages/home.html.erb
create app/views/static_pages/help.html.erb
invoke test_unit
create test/controllers/static_pages_controller_test.rb
invoke helper
create app/helpers/static_pages_helper.rb
invoke test_unit
invoke assets
invoke coffee
create app/assets/javascripts/static_pages.coffee
invoke scss
create app/assets/stylesheets/static_pages.scss
私の場合はspringを再度起動しなくてもrails generateが実行できました。