Ruby on Rails latest stable (v6.1.7.7) - 0 notes

Module deprecated or moved

This module is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here.

Rails::Generator is a code generation platform tailored for the Rails web application framework. Generators are easily invoked within Rails applications to add and remove components such as models and controllers. New generators are easy to create and may be distributed as RubyGems, tarballs, or Rails plugins for inclusion system-wide, per-user, or per-application.

For actual examples see the rails_generator/generators directory in the Rails source (or the railties directory if you have frozen the Rails source in your application).

Generators may subclass other generators to provide variations that require little or no new logic but replace the template files.

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.

The layout of generator files can be seen in the built-in controller generator:


The directory name (controller) matches the name of the generator file (controller_generator.rb) and class (ControllerGenerator). The files that will be copied or used as templates are stored in the templates directory.

The filenames of the templates don’t matter, but choose something that will be self-explanatory since you will be referencing these in the manifest method inside your generator subclass.

Show files where this module is defined (9 files)
Register or log in to add new notes.