How to create your own rail generator without the need for argumentation?

I seem to be stuck figuring out that my generator doesn't need an argument. So, for example, my generator code:

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

But when I do rails g my, rails always asks for an extra argument. Can you show me how this does not require additional arguments?

Thank.

+3
source share
1 answer

You should use class MyGenerator < Rails::Generators::Baseinsteadclass MyGenerator < Rails::Generators::NamedBase

+6
source

Source: https://habr.com/ru/post/1788691/


All Articles