'rails generate' commands hang when trying to create a model

后端 未结 6 687
时光取名叫无心
时光取名叫无心 2021-01-30 06:14

I\'m new to rails and decided this morning to dump my whole database design/model and start over. And being a noob, I\'m sure did it incorrectly.

I removed all the files

6条回答
  •  误落风尘
    2021-01-30 06:57

    If your rails generate commands hangs, it is most likely that the generated binstubs of rails are the issue. As you mentioned, you renamed the project.

    My educated guess is that some paths in the binstubs were still set to the old project directory but did not exist any longer.

    There is a great article on how binstubs work here: https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs

    rails 4

    To reset the binstubs, just delete your bin/ directory in rails and run:

    # generates binstubs for ALL gems in the bundle
    bundle install --binstubs
    
    # ...OR, generate binstubs for a SINGLE gem (recommended)
    bundle binstubs rake
    

    rails 5/rails 6

    To reset the binstubs, just delete your bin/ directory in rails and run:

    rake app:update:bin
    

    Why do we need to use the 'rake' command for rails 5 and higher, and not the 'rails' command itself?

    Since rails 5 some 'rake' commands are encapsulated within the 'rails' command. However when one deletes 'bin/' directory one is also removeing the 'rails' command itself, thus one needs to go back to 'rake' for the reset since 'rails' is not available any longer but 'rake' still is.

提交回复
热议问题