Search code examples
ruby-on-railsrubyrubygemsgenerator

How to get generators call other generators in rails 3


I am experimenting with gem development, right now specifically generators. So far I have successfully created two generators that do their job just perfectly. These two generators are in the same directory.

However, right now I have to call each of them separately.

What I'd like to do is just call one generator and have that generator call all the other ones. Just would type

rails g generator_name

and this would call x other generators.

Does anyone know how would I got about doing this?

Help is much appreciated, thanks!


Solution

  • In your generator, you can just call

    generate "some:generator" # can be anything listed by 'rails g'
    

    for example:

    module MyGem
      class InstallGenerator < Rails::Generators::Base
    
        def run_other_generators
          generate "jquery:install" # or whatever you want here
        end
    
      end
    end
    

    By the way, if you are working on Rails 3 gems, this question can also help out:

    Rails 3 generators in gem