Rails generate doesn't work anymore?

Hi there,

I can’t use rails generate (or rails g) command anymore. I’ve got a lot of options but no generate options seems to be possible anymore. I’m on rails 6.0.3.4.

Do I miss something here?

Thanks.

When you are issuing these commands, is your terminal “in” a Rails project directory? The rails g(enerate) command is only active and usable when you are in a Rails project. rails new should work everywhere.

Walter

Hi,

Of course I’m in a rails project. Rails new is not a problem but when I use rails generate or g (in a rails project) it outputs me a help page with all the possible commands. But the generate option isn’t visible. I’ve just upgraded rails and removed my “test” project and created it again within a dos terminal (not powershell) and it works properly. Strange behaviour. It’s solved in the meantime thanks.

Okay, then, can you repeat this in an absolutely new rails project that you just created? Are you using any of the dozens of flags when you create the new project? I can’t recall there being an option to disable generators, but hey, maybe that’s one of the options??? Usually, you will only see the wall of text if you try to run a rails command (besides new) outside of a rails project. If you try to run rails generate without arguments, or with a malformed argument, you’ll usually get an error or stack trace.

What version of rails do you see when you type rails -v all by itself?

Walter

Huh? I’ve never seen rails g by itself produce anything but a usage page, e.g.:

08:31 ~/testcases/rails/rails-6/samurai:(main) $ rails g
Usage: rails generate GENERATOR [args] [options]
...

P.S. Generating a scaffold on a fresh install (Ruby 2.7.2, Rails 6.1.2) as above works as expected here.

[quote=“soufianta McDVOICE”]

Hi there,

I can’t use rails generate (or rails g) command anymore. I’ve got a lot of options but no generate options seems to be possible anymore. I’m on rails 6.0.3.4.

Do I miss something here?

Thanks. [/quote]

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!