我正在編寫一個Rails 3.2生成器,並希望使用Thor::Shell::Basic實例方法(例如,ask
或yes?
),就像他們在official Rails guides on Application Templates中所做的一樣。如何在Rails Generator中使用Thor :: Shell :: Basic?
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"
東西是不正確設置,雖然我用發電機產生髮電機...