spring icon indicating copy to clipboard operation
spring copied to clipboard

Can't generate rails 5 models without doing `spring stop`

Open mcshakes opened this issue 9 years ago • 12 comments

When trying to generate new models, it would hang there until I was forced to abort with ctrl-c. I got these error logs

$ rails g scaffold book title 'price:decimal{5,2}' author:references publisher:references{polymorphic}
^C/Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/client/run.rb:117:in `gets': Interrupt
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/client/run.rb:117:in `verify_server_version'
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/client/run.rb:62:in `run'
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/client/run.rb:42:in `warm_run'
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/client/run.rb:35:in `call'
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/client/command.rb:7:in `call'
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/client/rails.rb:24:in `call'
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/client/command.rb:7:in `call'
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/client.rb:30:in `run'
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/bin/spring:49:in `<top (required)>'
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `load'
    from /Users/edmac/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>

So I did spring stop, and retried the above generator to get this:

Running via Spring preloader in process 78027
      invoke  active_record
      create    db/migrate/20160714015808_create_books.rb
      create    app/models/book.rb
      invoke    test_unit
      create      test/models/book_test.rb
      create      test/fixtures/books.yml
      invoke  resource_route
       route    resources :books
      invoke  scaffold_controller
      create    app/controllers/books_controller.rb
      invoke    test_unit
      create      test/controllers/books_controller_test.rb

Considering how little I know about Spring, and whether something else will break later, I'm wondering if I did something wrong in the process of upgrading my Ruby version, my bundler and upgrading to Rails 5. Or if this is more of an issue local to Spring. Let me know if you need any more details.

mcshakes avatar Jul 15 '16 20:07 mcshakes

Can confirm. Found this when searching for an analogous error when generating controllers. This does not affect Rails 5 on my Linux Mint amd64 desktop, but does affect Rails 5 on my ARM Chromebook with Debian Jessie chroot.

Edit: Actually, I ran spring stop, tried again, and rails g complained of a syntax error in my routes.rb. I forgot a do. Still not sure why that error didn't come up the first time and rails g hanged.

ghost avatar Sep 13 '16 18:09 ghost

I just ran into this myself. What I found was that rails g model fails if you don't have ActiveRecord or Mongo installed. I had built a rails 5 api project with --skip-active-record and I can generate controllers but not models.

fuzzygroup avatar Jan 12 '17 11:01 fuzzygroup

This just happened to me as well (Rails 5.1).

daqo avatar Feb 24 '17 16:02 daqo

@mcshakes I solved my problem with like this in root project.

I have used Rails 5.1 with module --api

echo "--skip-spring" >> ~/.railsrc

thadeu avatar Jun 08 '17 20:06 thadeu

With spring, all my rails generate commands hang. 😞

ivawzh avatar Dec 20 '18 01:12 ivawzh

With spring, all my rails generate commands hang. disappointed

Same problem with Rails 5.2.2, Spring 2.0.2 and ruby 2.3. Need to call spring stop before running any generator. Can be demonstrated with with clean new Rails app, adding the devise Gem and then running rails generate devise:install

brodjustice avatar Feb 19 '19 00:02 brodjustice

Seems like the problem could be with spring losing track of the environment. If I do this

  1. rails new myapp -d postgresql
  2. cd myapp
  3. Add gem 'devise' to Gemfile
  4. bundle install
  5. su - someotherid
  6. exit
  7. rails generate devise:install

Then spring will cause 7) to hang. But if I miss out 5) and 6) everything works fine.

brodjustice avatar Feb 19 '19 01:02 brodjustice

These kinds of errors have been happening for years. Everyone I know just uninstalls Spring from their Rails projects. We need a testing box that automates if all of the Rails commands work when Spring is installed. Tests need run on all major Operating Systems.

natesire avatar Mar 12 '19 14:03 natesire

Hey everyone, not sure I'm in the right place, but my searches have led me here.. Im having issues with rails generate migration, which worked perfectly for years until I upgraded to ruby 2.6.5

➜  esl_search git:(updateaddress) spring stop                                                                                                                                                       [2.6.5]
Spring stopped.
➜  esl_search git:(updateaddress) rails generate migration RemoveAdsFromConsultations address:string                                                                                                [2.6.5]
warning package.json: No license field                                                                                                                                                                     
warning No license field                                                                                                                                                                                   
Running via Spring preloader in process 51640
Traceback (most recent call last):
/usr/local/Cellar/rbenv/1.1.2/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork': cannot load such file -- rails/generators/migration/migration/migration_generator (LoadError)
/usr/local/Cellar/rbenv/1.1.2/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork': undefined method `reject!' for nil:NilClass (NoMethodError)
/usr/local/Cellar/rbenv/1.1.2/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork': undefined method `join' for nil:NilClass (NoMethodError)
/usr/local/Cellar/rbenv/1.1.2/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork': undefined method `reject!' for nil:NilClass (NoMethodError)
/usr/local/Cellar/rbenv/1.1.2/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork': undefined method `reject!' for nil:NilClass (NoMethodError)
/usr/local/Cellar/rbenv/1.1.2/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork': undefined method `reject!' for nil:NilClass (NoMethodError)

stop spring is not working for me.. any ideas? Thanks

matthewgoodwin avatar Feb 26 '20 09:02 matthewgoodwin

Kill spring with ps auwwx | grep spring to get the pid and then kill -9 pid (this should be the pid)

fuzzygroup avatar Feb 26 '20 09:02 fuzzygroup

Kill spring with ps auwwx | grep spring to get the pid and then kill -9 pid (this should be the pid)

thanks for the reply; I'm a total noob with spring and associated commands. are you saying ps auwwx | grep spring followed by kill -9 pid in the terminal?? also what could be the cause of the initial problem? Thanks again!

matthewgoodwin avatar Feb 26 '20 09:02 matthewgoodwin

For anyone landing here having the same problems as matthewgoodwin:

https://stackoverflow.com/a/56241794/6751482 fixed the very same issue for me.

Simply stopping spring did not seem to work in this case.

PrangerStefan avatar Feb 24 '21 09:02 PrangerStefan