rails generate が全然動かない!時に試すこと


railsでコントローラーを作ろうと思ったら...

Rails 6.0.3.1 にて
いいね機能を実装すべく、likes_controller.rbを作りたくて以下のコマンドを実行しました。

$ rails g controller likes

...うんともすんとも言わない

止めよう(^Cぽち)

^CTraceback (most recent call last):
    16: from bin/rails:3:in `<main>'
    15: from bin/rails:3:in `load'
    14: from /リポジトリ名/bin/spring:15:in `<top (required)>'
    13: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
    12: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
    11: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
    10: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
     9: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
     8: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
     7: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
     6: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/client/rails.rb:24:in `call'
     5: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
     4: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/client/run.rb:35:in `call'
     3: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/client/run.rb:42:in `warm_run'
     2: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/client/run.rb:62:in `run'
     1: from /Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/client/run.rb:117:in `verify_server_version'
/Users/ユーザー名/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/spring-2.1.0/lib/spring/client/run.rb:117:in `gets': Interrupt

うわ
どうやらspringというのが怪しい

解決方法

springを止めちゃいます。

$ spring stop
Spring stopped.

止まります。
rails g を再度実行!

$ rails g controller likes
Running via Spring preloader in process 23035
      create  app/controllers/likes_controller.rb
      invoke  erb
      create    app/views/likes
      invoke  test_unit
      create    test/controllers/likes_controller_test.rb
      invoke  helper
      create    app/helpers/likes_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    scss
      create      app/assets/stylesheets/likes.scss

できた

ちなみに

さっき止めたspringですが、ステータスを確認するとしっかり動いていると思います。

$ spring status
Spring is running:

参考