Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 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 so it doesn't need an extra argument?

Thanks.

like image 565
David Ang Avatar asked Jan 29 '11 15:01

David Ang


1 Answers

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

like image 156
jrichardlai Avatar answered Oct 09 '22 09:10

jrichardlai