I have created my own scaffold generator, now it's sitting in my ~/.rails/generator/scaffold directory. How can I make a gem in order to use my generator along other machines I'm using, without the need of copying the ~/.rails folder on every box ? I will push later the gem on Github
From the documentation:
For a RubyGem, put your generator class and templates in the lib directory. For a Rails plugin, make a generators directory at the root of your plugin.
However that's a little vague.
From the Rails::Generator::Lookup source:
Rails application. If RAILS_ROOT is defined we know we're generating in the context of a Rails application, so search RAILS_ROOT/generators.
Look in plugins, either for generators/ or rails_generators/ directories within each plugin
User home directory. Search ~/.rails/generators.
RubyGems. Search for gems named *_generator, and look for generators within any RubyGem's /rails_generators/_generator.rb file.
Builtins. Model, controller, mailer, scaffold, and so on.
A single generator gem should be structured like this:
- my_scaffold_generator/
- lib/
- my_scaffold_generator.rb
- required_file.rb
- templates/
- ...
Gems that contains multiple generators should be structured like this:
- my_cool_generators/
- rails_generators/
- cool_scaffold/
- cool_scaffold_generator.rb
- lib/
- required_file.rb
- ...
- templates/
- ...
- cool_controller/
- cool_controller_generator.rb
- lib/
- required_files.rb
- ...
- templates/
- ...