【发布时间】:2012-12-03 00:00:05
【问题描述】:
我正在编写 Rails 3.2 生成器,并希望像在 official Rails guides on Application Templates 中那样使用 Thor::Shell::Basic 实例方法(例如 ask 或 yes?)。
module MyNamespace
class ScaffoldGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
if yes? "Install MyGem?"
gem 'my_gem'
end
run 'bundle install'
end
end
这会给我一个NoMethodError: undefined method 'yes?' for MyNamespace::ScaffoldGenerator:Class。
我想不出一个干净的方法来使这些实例方法可用 - 我已经从 Rails::Generators::Base 继承。
编辑:
啊,这可能与托尔无关……我收到警告:
[WARNING] Could not load generator "generators/my_namespace/scaffold/scaffold_generator"
虽然我使用生成器来生成生成器,但有些东西设置不正确...
【问题讨论】:
标签: ruby-on-rails ruby thor