Thursday, March 08, 2007

Creating Controller with actions

The process for creating a controller is always the same:
$ ruby script/generate controller contollername actionname
This command accomplishes several tasks:
■ It creates a file named app/controllers/controllername_controller.rb.
■ It inserts an empty method definition for the actionname action into that file.
■ It creates a file called app/views/controllername/actionname.rhtml, which will be the file in which you place the ERb template code for this view.

或者先只创建controller以后再创建action:
$ ruby script/generate controller controllername

The majority of controllers correspond directly to an entity model: If there’s a“work” controller, then there’s probably a “work” model.

No comments: