如何在不需要参数的情况下创建自己的rails生成器?

Dav*_*Ang 4 ruby-on-rails generator

似乎我陷入困境,以便我的发电机不需要参数.所以例如我的生成器代码是这样的:

class MyGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)

  def generate_stylesheet
     copy_file "my.css", "public/stylesheets/my.css"    
  end
end
Run Code Online (Sandbox Code Playgroud)

但是当我做rails g my轨道时总是要求额外的争论.你能告诉我怎么这么不需要额外的论证吗?

谢谢.

jri*_*lai 7

你必须使用class MyGenerator < Rails::Generators::Base而不是class MyGenerator < Rails::Generators::NamedBase