The base generator for named components: models, controllers, mailers, etc. The target name is taken as the first argument and inflected to singular, plural, class, file, and table forms for your convenience. The remaining arguments are aliased to actions as an array for controller and mailer convenience.

Several useful local variables and methods are populated in the initialize method. See below for a list of Attributes and External Aliases available to both the manifest and to all templates.

If no name is provided, the generator raises a usage error with content optionally read from the USAGE file in the generator’s base path.

For example, the controller generator takes the first argument as the name of the class and subsequent arguments as the names of actions to be generated:

./script/generate controller Article index new create

See Rails::Generator::Base for a discussion of manifests, Rails::Generator::Commands::Create for methods available to the manifest, and Rails::Generator for a general discussion of generators.

Methods
A
B
N
Attributes
[R] class_name
[R] class_nesting
[R] class_nesting_depth
[R] class_path
[R] file_name
[R] file_path
[R] name
[R] plural_name
[R] singular_name
[R] table_name
Class Public methods
new(runtime_args, runtime_options = {})
# File rails/railties/lib/rails_generator/base.rb, line 202
def initialize(runtime_args, runtime_options = {})
  super

  # Name argument is required.
  usage if runtime_args.empty?

  @args = runtime_args.dup
  base_name = @args.shift
  assign_names!(base_name)
end
Instance Protected methods
attributes()
# File rails/railties/lib/rails_generator/base.rb, line 219
def attributes
  @attributes ||= @args.collect do |attribute|
    Rails::Generator::GeneratedAttribute.new(*attribute.split(":"))
  end
end
banner()

Override with your own usage banner.

# File rails/railties/lib/rails_generator/base.rb, line 215
def banner
  "Usage: #{$0} #{spec.name} #{spec.name.camelize}Name [options]"
end