“rails generate” not working

2020-02-16 06:35发布

问题:

When using ruby 2.1.0 (or 2.1.1) and I type rails g nothing happens. It simply hangs. But when I change to 1.9.3, using rvm use 1.9.3 it works as expected.

How can I debug this? What might be causing this command to hang, only on ruby > 2.0.0?

I have tried reinstalling both rails and ruby!

回答1:

Have you tried to run:

spring stop

rails generate hangs may because spring is already running.

see https://github.com/rails/spring/issues/265



回答2:

I tried all of this and it didn't work for me. Turns out that I had a bad rails file in my /bin folder.

This is what I had:

#!/usr/bin/env ruby
begin
  load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require 'bundler/setup'
load Gem.bin_path('rails', 'rails')

And I just recreated a new rails app and copied the proper one:

#!/usr/bin/env ruby
begin
  load File.expand_path("../spring", __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'

This worked for me!