TodoList: scaffold の --help2006年12月12日 14時40分44秒

実はあの後、他にも奇妙な事に気が付いた。

app/controllers/todo_controller.rb に :scaffold を書いたときには http://localhost:3000/todo/list にアクセスしていた。しかし、ruby script/generate scaffold Todo をやったら app/views/todos が出来たのだ。

そして、調べていたら、偶然 で以下のような記述を見つけた。

% ruby script/generate jascaffold kid test

引数は scaffold と同じで、モデル名、コントローラ名、View名、、、。(kids というテーブルを想定しています)。

その後、


% ruby script/generate scaffold todo todo
...
% ruby script/generate scaffold todo todo list
...
% ruby script/generate scaffold todo todo list.rhtml
...

とやってみたが、生成されたファイルはどれも同じであった。_form.rhtml、list.rhtml、show.rthml、nrw.rhtml、edit.rhtml が出来るようだった。

やはり、script/generate scaffold で何が起こるのか良く分からない。そこで、焼けになって、generate を適当に試していると、


% ruby script/generate scaffold --help
Usage: script/generate scaffold ModelName [ControllerName] [action, ...]

General Options:
    -p, --pretend                    Run but do not make any changes.
    -f, --force                      Overwrite files that already exist.
    -s, --skip                       Skip files that already exist.
    -q, --quiet                      Suppress normal output.
    -t, --backtrace                  Debugging: show backtrace on errors.
    -h, --help                       Show this help message.
    -c, --svn                        Modify files with subversion. (Note: svn mu
st be in path)
Description:
    The scaffold generator creates a controller to interact with a model.
    If the model does not exist, it creates the model as well.  The generated
    code is equivalent to the "scaffold :model" declaration, making it easy
    to migrate when you wish to customize your controller and views.

    The generator takes a model name, an optional controller name, and a
    list of views as arguments.  Scaffolded actions and views are created
    automatically.  Any views left over generate empty stubs.

    The scaffolded actions and views are:
        index, list, show, new, create, edit, update, destroy

    If a controller name is not given, the plural form of the model name
    will be used.  The model and controller names may be given in CamelCase
    or under_score and should not be suffixed with 'Model' or 'Controller'.
    Both model and controller names may be prefixed with a module like a
    file path; see the Modules Example for usage.

Example:
    ./script/generate scaffold Account Bank debit credit

    This will generate an Account model and BankController with a full test
    suite and a basic user interface.  Now create the accounts table in your
    database and browse to http://localhost/bank/ -- voila, you're on Rails!

Modules Example:
    ./script/generate scaffold CreditCard 'admin/credit_card' suspend late_fee

    This will generate a CreditCard model and CreditCardController controller
    in the admin module.

と出てきた。どうも、まだ理解しきれてはいないが、これがこの先も重要な役割を果たしそうなのは例を見て思った。

前回次回