Rails Spring breaking generators

ぐ巨炮叔叔 提交于 2019-11-29 01:03:43

Check directories of some other projects that you were working on at that time, chances are that the generated files ended up there.

spring seems to get confused when you work with more than one rails app at a time. That's probably what caused your problem

spring runs as a server and keeps a rails environment loaded. I think what happens is that if you work with more than one project at a time then spring system seems to get confused and uses wrong environment.

I have had a situation where I was running rails g ... in one project and the files were getting generated in another project. What was crazy was that I kept renaming and moving that other folder, and still the generator kept putting the files in that folder. As if spring had latched on the the inode of that folder.

Try DISABLE_SPRING=1 rails g devise:install

or ps aux |grep spring and kill all the processes you see and then run rails g devise:install

We are taking out spring from the Gemfile for now while this broken behavior persists, and in the future use rails new --skip-spring

If you want to keep using spring, then try following these rules

  • Use new shells for each new project
  • Use a new directory name for each new project (If you do rails new blog, work on it, then mv blog blog.old and rails new blog again, it might not work.
  • From time to time keep on killing all the spring servers, for safety's (and sanity's) sake.

You can disable spring for any $ rails command by passing the environment variable DISABLE_SPRING=1.

$ DISABLE_SPRING=1 rails generate devise:install

Alternatively, you can try $ spring stop to spin down the spring processes. Running $ rails generate afterwards will spin up a new spring process, which might solve the temporary issue.

There is same problem on rails 5.1.4 for responders gem

I listed solutions along with previous ones:

  • close terminal and open new one
  • run command with
    DISABLE_SPRING=1 bundle exec rails generate responders:install
    or export it as environment variable
    export DISABLE_SPRING=1
  • kill running spring process for your app
    ps ax | grep spring | grep YOUR_APP_NAME | cut -f1 -d' ' | xargs kill

This is an old post, but i think my experience might help someone...

rails 5.0.1

I was facing same issue after i messed up some devise generated files(i am new to rails and learning) and than i tried rails destroy devise model and i was stuck, tried many time and nothing worked.

Googled, got here, tried excluding spring gems, and it worked, again added spring gems, and devise was again stuck on everything.

I just closed the terminal and opened new one, and it worked.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!