Randomba Scaffold

A collection of hacks to the Rails scaffold generator, to make it output code the way I use it in my projects. You may like some of it, and may hate other parts. You’re free to use it under the terms of the MIT license if the parts you like outweigh the parts you hate.

This scaffold generator does the same thing as the default Rails scaffold generator, with a few differences.

Differences from Rails Scaffolding:

Controller

  • Loads object with a before_filter to be DRYer.
  • Adds placeholder permission checking before_filters on all actions.
  • “Destroy” method handles error conditions.
  • Actions are alphabetized for more obvious consistency.

Controller Test

  • Tests error conditions, not just the “happy-path.”
  • Has 100% code coverage with RCov.
  • Simplifies test method names and alphabetizes them for more obvious consistency.
  • Uses some very simple mocking with mocha to limit calls to the DB.

Views

  • Have cleaner, more semantic XHTML.
  • Are broken up into a couple of partials to be DRYer.
  • Use will_paginate.

Misc

  • Doesn’t generate a layout or CSS file.

Installation

There are three ways you can install this generator:

Gem

sudo gem install norman-randomba-scaffold

- or -


git clone git://github.com/norman/randomba-scaffold.git
cd randomba-scaffold
gem build randomba_scaffold.gemspec
sudo gem install randomba_scaffold-*.gem

Manual

Download the tarball from the Github repository and unarchive it in ~/.rails/generators.

Plugin

./script/plugin install git://github.com/norman/randomba-scaffold.git

Dependencies

The generated code will depend on:

You’ll need to add the gems and or requires to your config/environment.rb manually.

Author

Norman Clarke

This work is derived from code in Ruby on Rails and is released under its same license, the MIT License.