woensdag 29 april 2009

Ruby on Rails 2.0 Scaffold

The scaffold generator is not as easy to use anymore in Rails 2.0 as it was in the previous version. Instead of working directly with database tables, now it only works with migrations. The use of migrations is a good thing in my opinion, because migrations keep it easy to track and apply database changes. What I don't like about the renewed scaffold generator is that you have to put all the fields you want to have in your table in the command line. If you create your own migration files, scaffold simply doesn't work. This may be OK with small tables, but if you have tables with lots of fields it is much easier to make the migration file your self. Putting all table fields on the command line doesn't give a good view of all the fields, and you won't notice if you forgot a field.

An example of a scaffold generation:

> ./script/generate scaffold ModelName field1:type field2:type field3:type