Monday 4 December 2006

Moist scaffold

I've just discovered dry_scaffold and it's lots of fun. It does exactly what a scaffold was originally intended for: ie to hold the basic shape of the CRUD bits of a rails application while you get around to replacing the bits that need replacing.

This is as opposed to the rails-standard script/generate scaffold, which generates tons of files that you may not be ready to (or may not ever) change. IMO the standard scaffold-generator is less like a scaffold, and more like a rough-shaped mud-hut slapped quickly together that you can modify.

Unfortunately, if you need more than one of these, you get several nearly-identical rough mud-huts piled randomly about the place. They each begin with their own complete set of infrastructure which you can (try) to modify to be more DRY, but tends to end up with some residual wetness that is just really hard to get rid of without a lot of effort.

By contrast, dry_scaffold adds new model objects like storeys in a high-rise (with shared ventilation and lifts and... ok, I'm going too far now). The basic infrastructure is shared because it's all contained in the engine. Much DRYer.

All this being said, it's still quite new and so has its issues. The main one that I see is the spotty documentation. So here's a rough guide for where to go looking:

  • To get the basic dry_scaffold up and running, use the standard dry_scaffold page, but use your own model (obviously) and ignore where it says to update layouts/admin.rhtml.
  • If you need to only slightly adjust how the fields are added/listed or filtered, you have a range of options available to you. The data are stored in your model object as a set of columns with configuration options. Check out the has_column rDoc to see all the options available. The rDoc is available here, and has_column is listed in the frame at top-right.
  • If you need to do some serious readjustment of the code, or plan on using dry_scaffold simply as the stop-gap while you replace the structure, then you really need a "moist" scaffold. You will need to run the generate command with the following form: script/generate dry_scaffold ModelName ControllerName less_dry. This will generate a minimal controller that allows you to override/extend any actions you need; while continuing to be extremely slim-line. AFAIK there is no documentation on this, but from general mucking about it seems straight-forward.
  • If you have more questions, there is a forum available here.

No comments: