Sunday, February 24, 2008

Tips to use scaffold generator of rails 2.0

There are big differences for the scaffold between rails 2.0 and rails rails 2.0 scaffold", like me, you can find a lot of good blogs or articles to learn about the new ways to use rails 2.0 scaffold. Anyhow, I would like to add some basic tips here, which I used a lot.

Number one tip is to use the help from rails itself:
script/generate scaffold -h

In rails 1.x, I created model and table in db firstly then do the scaffold, now the generator can do the model and table in the same time. The way to keep your old habit is to use:
> script/generate scaffold category(or other model name) --skip-migration

In the views, I need add the _form.html.erb by myself.

The generator will also put a map.resources in your routes.rb. If I want to add new actions such as batch_new and batch_create into this categories_controller. Config the routes.rb:
map.resources :categories,
:collection => {:batch_new => :get, :batch_create => :post}

1 comment:

Unknown said...

It seems that it implements REST with default scaffold replacing the old scaffold_resource