2014-02-05 82 views
0

我知道如何創建一個軌道發電機的寶石被稱爲像:如何創建命令行導軌生成器gem?

rails g my_generator command 

而且我知道如何創建一個托爾寶石,可以這樣調用:

my_generator command 

但我不知道如何創建可以使用可執行文件調用的軌道生成器。我已經通過創建像一個lib/my_generator/cli.rb文件的嘗試:

require 'thor' 

module Mang 
    class Cli < Thor 
    include ::Rails::Generators::Base 

    desc "install_gem", "install a gem" 
    def install_gem 
     gem 'thor', "0.18.1" 
    end 

    end 
end 

,但我得到了下面的錯誤,儘管有增加的Rails在我gemspec的依賴。

uninitialized constant Rails (NameError) 

回答

0

該修復只是包含rails/generators/actions模塊的問題。

require 'thor' 
require 'rails/generators' 
require 'rails/generators/actions' 

module Mang 
    class Cli < Thor 
    include Thor::Actions 
    include Rails::Generators::Actions 

    desc "install_gem", "install a gem" 
    def install_gem 
     gem 'thor', "0.18.1" 
    end 

    end 
end