Custom Rails Scaffold

August 30th, 2006 by Strawp

A short while ago I mentioned creating custom scaffolds for Rails to cut out all the tweaking you need to do to the layouts for each object in the project. It was pretty easy to do, but I put off uploading the scaffold for a while because there were a few tweaks to do and then that massive bug in Rails was discovered so I’ve just gone through and made sure the code doesn’t clash with anything in 1.1.6

What I’ve done is largely changes on the semantic HTML / code neatness side of things. That is:

– Switched a lot of the tables (semantically fine, but not flexible) for lists
– Added a “confirm” action which replaces “destroy” and provides a seperate page with the confirm form on it
– A lot of things are now list items – navigation etc
– Added some useful class names to elements
– Dropped the H1s at the top of each page to H2s
– Created a layout with header, footer, main. Header contains the H1
– Hidden the flash element unless it’s actually used
– Removed nearly all of the default stylesheet. Styling happens after coding! 😉
– Made forms more semantically correct (labels and fields)

These are all changes I would have done manually after the default scaffold.

To use this, download the custom scaffold archive and unzip it to a folder next to the default scaffold. On my machine, at the time of writing I have it in: C:\\ruby\\lib\\ruby\\gems\\1.8\\gems\\rails-1.1.6\\lib\\rails_generator\\generators\\components\\custom_scaffold.

Then, instead of running script/generate scaffold, you run script/generate custom_scaffold.

You might want to edit the file layout.rhtml as it currently says “Site by Iain” at the bottom of every page.

let me know if this ends up being useful to you. (I’ve really got to get on and add a decent comments system to my site).

Comments are closed.