1

I'm trying to introduce the Vanity gem into a project and everything is happy right up until I try to run the generator. This is the call:

rails generate vanity

And this is the output:

Could not find generator 'vanity'. Maybe you meant 'vanity', 'task' or 'mailer' Run rails generate --help for more options.

Notice that it can't find 'vanity' and then suggests vanity. Wut? I then took a moment to verify that the generator actually exists:

rails generate --help | grep "anity"

and got:

Vanity:
vanity
vanity:views

I am using Spring, so I stopped that with spring stop.

I should also note that I tried a bunch of things like:

rails generate Vanity:vanity
rails generate vanity:vanity
rails generate Vanity
rails generate oh:please:do:vanity

Additionally, I am actually using bundler so I tried ALL these things with and without bundle exec at the beginning of the commands.

I wonder if perhaps this error is actually masking an issue in my local setup, but I've looked really closely and am convinced that the installation and setup of vanity is correct.

Version information:

ruby 2.5.5p157
Rails 5.2.3
Vanity 3.0.0

EDIT: additional information: I went down the path of stopping the Spring server, bundle update and then trying the generator--nothing changed. I've even tried going into the actual generator and debugging there. While it loads the file, it never executes any of the methods.

jaydel
  • 14,389
  • 14
  • 62
  • 98
  • dug in closer and it was unable to resolve the generator class at all. I created an initializers/vanity.rb file and required the generator file in there. seems a tad cheesy but it is what it is. – jaydel Jul 25 '19 at 16:42

1 Answers1

1

Solved this on my own. It turns out that the vanity gem wasn't automatically pulling the generators into the load path. That means that when the generator was called, it was erroring out because it couldn't find the actual generator class in the first place.

The generator error was masking that error and making it look like the generator itself couldn't be found.

The fix for this was to explicitly require the generators in a config/initializers/vanity.rb file.

The vanity gem claims that in Rails apps the classes are "automagically" available.

jaydel
  • 14,389
  • 14
  • 62
  • 98