我有一个宝石,我需要使用Rails 2和3,我试图让生成器现在为Rails 2工作,Rails 3生成器工作正常。我有一个目录结构,如:
gem_name
- generators
- gem_name
- gem_name_generator.rb <- Should be Rails 2 generator
- templates
- lib
- generators
- gem_name
- gem_name_generator.rb <- Working Rails 3 generator
- templates
我无法让我的生成器显示在script/generate
或bundle exec script/generate
我的Rails 2 Generator的代码如下:
class GemNameGenerator < Rails::Generator::Base
def add_options!(opt)
opt.on('-k', '--api-key=key', String, "Your API Key") { |v| options[:api_key] = v}
end
def manifest
if !options[:api_key]
puts "Must pass --api-key"
exit
end
record do |m|
m.template 'initializer.rb', 'config/initializers/my_gem.rb', :assigns => {:api_key => options[:api_key]}
end
end
end