Regenerating Rails Scaffolding for 2.1.0

The concept of scaffolding in Rails 2.1.0 has been bugging me for a while and I haven’t been able to find out much about it online (at least what I wanted to know), so I am going to address my issues. I have been designing an app on rails that doesn’t fit the normal rails model as snugly as it should and am building the model level first and making sure everything works on the command line before I even bother with the GUI.

Now, as I am completing a side project, I am realizing that I should work to make this conform to the standard Rails model rather than trying to pervert rails into doing things my way. After I realized this, I decided that I wanted to generate the scaffolds for each of my models (although my models and migrations were already pretty far along). I have the whole thing under version control backed up two different ways daily (self => :paranoid), but I still didn’t like the idea of my complicated models getting overwritten by the scaffold generator (even though I was pretty sure they wouldn’t be).

For those of you rails devs living in the stone age, the good old ’scaffold :modelname’ is gone with 2.x (although it is available as a plugin), but the script/generate scaffold command is still around. For dynamic scaffolding, I prefer active_scaffold to the 1.x version anyway. So I took the plunge and here’s what I found out.

Running ‘ruby script/generate scaffold <name>’ after you already have models created:

  1. Leaves all your existing stuff alone (you have to ruby script/destroy whatever you want to generate that is already there)
  2. Will generate all the NICEUSD actions (new, index, create, edit, update, show, delete)
  3. Will generate all the views (edit, new, index, show) and the layout
  4. Will NOT generate any of the form fields for the views (you may be able to specify them though, however it won’t recreate the migration if there is already one there).
  5. Didn’t hurt my app… I didn’t even need to revert.

Leave a Reply