Search code examples
ruby-on-railsscaffolding

uninitialized constant Rails::Generators (NameError)


I'm updating the code for a generator that I wrote, but has been working fine until now.

When I simply rue the command

bundle exec rails g

I get the following error

/Users/mpierc200/projects/prototype_conflux/vendor/gems/itrc_client_files_generator-1.0.13/lib/itrc_client_files_generator.rb:6:in `<top (required)>':
uninitialized constant Rails::Generators (NameError)

The offending line is

class ItrcClientFilesGenerator < Rails::Generators::Base

My Rails version is

Rails 3.1.9

ruby version is

ruby 1.9.3p194

Solution

  • It looks like the Rails generator modules were pulled out and not automatically loaded at some point during Rails 3 development. This is probably for good reasons.

    You have to include them in custom generators:

    require 'rails/generators'
    
    class ItrcClientFilesGenerator < Rails::Generators::Base
      # Fancy generator code here
    end