开发者

how to create your own rails generator without needing an argument?

开发者 https://www.devze.com 2023-02-07 04:42 出处:网络
It seems that I am stuck figuring out so that my generator doesn\'t need an argument. So for instance my generator code is this:

It seems that I am stuck figuring out so that my generator doesn't need an argument. So for instance my generator code is this:

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

  def genera开发者_运维技巧te_stylesheet
     copy_file "my.css", "public/stylesheets/my.css"    
  end
end

But when I do rails g my rails always asks for an extra argument. Can you show me how so it doesn't need an extra argument?

Thanks.


You have to use class MyGenerator < Rails::Generators::Base instead of class MyGenerator < Rails::Generators::NamedBase

0

精彩评论

暂无评论...
验证码 换一张
取 消