提交 3236e15c 编写于 作者: D David Heinemeier Hansson

Updated the usage documentation for the generator actions for their new home

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@101 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 c7589559
......@@ -137,17 +137,15 @@ task :copy_configs do
end
task :copy_generators do
mkdir_p File.join(PKG_DESTINATION, 'script')
mkdir_p File.join(PKG_DESTINATION, 'script/generators')
SCRIPT_FILES.each do |file|
dest_file = File.join(PKG_DESTINATION, 'script', file)
cp File.join('generators', "#{file}.rb"), dest_file
chmod 0755, dest_file
end
mkdir_p File.join(PKG_DESTINATION, 'script/generators')
GENERATORS.each do |dir|
cp_r File.join('generators', dir), File.join(PKG_DESTINATION, 'script', dir)
cp_r File.join('generators', dir), File.join(PKG_DESTINATION, 'script', 'generators', dir)
end
end
......
NAME
new_controller - create controller and view stub files
GENERATOR
controller - create controller and view stub files
SYNOPSIS
new_controller ControllerName action [action ...]
generate controller ControllerName action [action ...]
DESCRIPTION
The new_controller generator takes the name of the new controller as the
The controller generator takes the name of the new controller as the
first argument and a variable number of view names as subsequent arguments.
The controller name should be supplied without a "Controller" suffix. The
generator will add that itself.
From the passed arguments, new_controller generates a controller file in
app/controllers with a render action for each of the view names passed.
It then creates a controller test suite in test/functional with one failing
test case. Finally, it creates an HTML stub for each of the view names in
app/views under a directory with the same name as the controller.
Controller generates a controller file in app/controllers with a render
action for each of the view names passed, a test suite in test/functional
with one passing test case, and HTML stubs for each view in app/views
under a directory with the same name as the controller.
EXAMPLE
new_controller Blog list display new edit
./script/generate controller Blog list display new edit
This will generate a BlogController class in
app/controllers/blog_controller.rb, a BlogHelper class in
app/helpers/blog_helper.rb and a BlogControllerTest in
test/functional/blog_controller_test.rb. It will also create list.rhtml,
test/functional/blog_controller_test.rb, and list.rhtml,
display.rhtml, new.rhtml, and edit.rhtml in app/views/blog.
The BlogController class will have the following methods: list, display, new, edit.
Each will default to render the associated template file.
The BlogController class will have list, display, new, and edit actions.
Each action will render the associated view by default.
NAME
new_mailer - create mailer and view stub files
GENERATOR
mailer - create mailer and view stub files
SYNOPSIS
new_mailer MailerName action [action ...]
generate mailer MailerName action [action ...]
DESCRIPTION
The new_mailer generator takes the name of the new mailer class as the
The mailer generator takes the name of the new mailer class as the
first argument and a variable number of mail action names as subsequent
arguments.
From the passed arguments, new_mailer generates a class file in
app/models with a mail action for each of the mail action names passed.
It then creates a mail test suite in test/unit with one stub test case
and one stub fixture per mail action. Finally, it creates a template stub
for each of the mail action names in app/views under a directory with the
same name as the class.
Mailer generates a class file in app/models with action methods for each
of the mail action names passed, a test suite in test/unit with a stub
test case and fixture per action, and template stubs for each action in
app/views under a directory with the same name as the class.
EXAMPLE
new_mailer Notifications signup forgot_password invoice
./script/generate mailer Notifications signup forgot_password invoice
This will generate a Notifications class in
app/models/notifications.rb, a NotificationsTest in
......
NAME
new_model - create model stub files
GENERATOR
model - create model stub files
SYNOPSIS
new_model ModelName
generate model ModelName
DESCRIPTION
The new_model generator takes a model name (in CamelCase) and generates
a new, empty model in app/models, a test suite in test/unit with one
failing test case, and a fixtures directory in test/fixtures.
The model generator takes a model name and generates an empty model in
app/models, a test suite in test/unit with one passing test case, and a
fixtures YAML file in the test/fixtures directory.
EXAMPLE
new_model Account
./script/generate model Account
This will generate an Account class in app/models/account.rb, an
AccountTest in test/unit/account_test.rb, and the directory
test/fixtures/account.
AccountTest in test/unit/account_test.rb, and the fixtures file
test/fixtures/account.yml.
NAME
new_scaffold - create a model and a skeleton controller
GENERATOR
scaffold - create a model and basic controller
SYNOPSIS
new_scaffold ModelName [action ...]
generate scaffold ModelName [action ...]
DESCRIPTION
The new_scaffold generator takes the name of the new model as the
The scaffold generator takes the name of the new model as the
first argument and an optional list of controller actions as the
subsequent arguments. Any actions with scaffolding code available
will be generated in your controller; others will be left as stubs.
The generated controller has the same code that "scaffold :model"
uses, so it's easy to migrate when you want to start customizing
your controller.
EXAMPLE
new_scaffold Account
./script/generate scaffold Account debit credit
This will generate the Account model with unit tests and fixtures,
the AccountController controller with actions, views, and tests for
index, list, show, new, create, edit, update, and destroy.
This will generate an Account model and controller.
Now create the accounts table in your database and browse to
http://localhost/account/ -- voila, you're on Rails!
......@@ -5,6 +5,12 @@
require 'rails_generator'
require 'test/unit'
# Railties test directory has RAILS_ROOT/generators instead of the expected
# RAILS_ROOT/script/generators, so override it manually.
old_verbose, $VERBOSE = $VERBOSE, nil
Rails::Generator.const_set(:CONTRIB_ROOT, "#{RAILS_ROOT}/generators")
$VERBOSE = old_verbose
class RailsGeneratorTest < Test::Unit::TestCase
BUILTINS = %w(controller mailer model scaffold)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册