rails / spring

Rails application preloader
MIT License
2.8k stars 339 forks source link

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

Open mcshakes opened 8 years ago

mcshakes commented 8 years ago

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.

ghost commented 8 years ago

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.

fuzzygroup commented 7 years ago

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.

daqo commented 7 years ago

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

thadeu commented 7 years ago

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

I have used Rails 5.1 with module --api

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

ivawzh commented 5 years ago

With spring, all my rails generate commands hang. 😞

brodjustice commented 5 years ago

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 commented 5 years ago

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.

natesire commented 5 years ago

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.

matthewgoodwin commented 4 years ago

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

fuzzygroup commented 4 years ago

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

matthewgoodwin commented 4 years ago

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!

PrangerStefan commented 3 years ago

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.