如何获得发电机,将其他发电机呼叫到Rails 3中 [英] How to get generators call other generators in rails 3

查看:69
本文介绍了如何获得发电机,将其他发电机呼叫到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

这将调用x个其他生成器.

and this would call x other generators.

有人知道我会怎么做吗?

Does anyone know how would I got about doing this?

非常感谢您的帮助,谢谢!

Help is much appreciated, thanks!

推荐答案

在生成器中,您只需调用

In your generator, you can just call

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

例如:

module MyGem
  class InstallGenerator < Rails::Generators::Base

    def run_other_generators
      generate "jquery:install" # or whatever you want here
    end

  end
end

顺便说一句,如果您正在使用Rails 3 gem,那么这个问题也可以帮助您解决问题:

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

在gem中设置3个生成器

这篇关于如何获得发电机,将其他发电机呼叫到Rails 3中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆