Ruby on Rails
ScaffoldGenerator

NOTE FOR RAILS 2.0.0+

Rails 2.0.0+ breaks chapter 1 of every existing quality rails tutorial because of scaffolding. instead of doing

  ./script/generate ( model -OR- controller ) Foo

instead run
  ./script/generate scaffold Foo somefieldname:integer anotherfieldname:string whateverfieldsyouwant:text

then do the

rake db:drop:all; 
rake db:create:all; 
rake db:migrate; 
rake test

dance.

Scaffolding in Rails before 2.0.0
The scaffold generator writes the same code that Rails dynamic scaffolding (scaffold some_model) uses, so you get to start from the boilerplate code and keep any changes you make.

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                      Keep is like a secret with /dev/null.

-t, --backtrace                  Debugging: show backtrace on errors.

-h, --help                       Show this help message.

Example

ruby script\generate scaffold Aircraft 
(note the not plural aspect)

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. (Starting in rails 0.14.2 controller name is not optional, omitting it generates a Nil error—really? This change of behavior is not documented in the CHANGELOG, or even the help for the program. Is it intended or a bug?). 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!

To see full scaffold usage run: script/generate scaffold

Modules Example:

./script/generate controller 'admin/credit_card' suspend late_fee

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

Rails version 0.10.0

Going further with scaffolds

Alternately you can use “ActiveScaffold

which provides all of the same functionality as the default scaffold generator but uses Ajax to make the scaffold easier to use. Here are some of the advantages of the AjaxScaffold:


Suggestion : Shouldn’t script/generate scaffold take an optional DB table name as an argument ? Temporarily renaming tables just to be allowed to use the generator sucks…

// If you don’t want to have rails generate the database you can always specify—skip-migration on as a parameter to script/generate scaffold

Suggestion to help with above: Create a database view based on the table

Question: does “generate scaffold” really emulate the “scaffold” method ?
If so, how do I merge two different scaffolded models in one controller?, like I’d do with

 scaffold :foo, :suffix=>true
 scaffold :bar, :suffix=>true

category: Generator


Attribute Types
The type parameter is normally one of the migrations native types, which is one of the following: :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean.

http://www.railsbrain.com/api/rails-2.0.2/doc/index.html?a=M001532&name=TableDefinition#column



//a dutch Scaffold article can be found here

//Scaffold in Rails 2.0
screencast