Joe McGlynn

Rails Scaffolding

One of the (many) handy things about Rails is scaffolding, this is a super quick way to get a quick-and-dirty UI to interact with your data models. I don’t think it is intended to be anything more that a starting point, and certainly never part of a "real" application. I’ve used it as a starting off point, and it allows you to replace it piecemeal, one action at a time.

One obvious limitation of scaffolding is that it doesn’t support relationships between models, it only lets you edit the individual table data, not the related data. Since it isn’t a production thing, that’s cool. There are some bolt-ons for Rails that do address the problems of dynamically creating prettier and more functional UIs.

AjaxScaffold is one I’d looked at briefly in the past, today I spent some time looking at ActiveScaffold (http://activescaffold.com/). This project just hit their RC1 status, my first impression is very positive.

For products we build here at CodeGear we have to develop icons, decorators, splash screens, installer billboards and other graphics. We collect everyone’s needs and then work with a graphics artist to get the images composed and reviewed. Using this as a basis for an application (and an opportunity to take ActiveScaffold for a spin), I decided to see what I could do to build a little app to manage this data.

I’ll give you the punch line first, I really didn’t write much code at all. 31 lines total, most of that is auto-generated stuff too. I decided to keep my schema simplistic. I have requests, which have information about the image request like size, what it will be used for, when it’s needed and so forth. It has relations to "lookup tables" for things like status, project name, requester name, etc. It also has a list of images that come back from the artist for each request. It’s not uncommon that the first image isn’t spot-on, the developer give feedback and the artist produces another image. So I have an items model to store the image, comments and feedback. All pretty simple.

So my application consists of 5 models, which just contain the has_many and belongs_to relationship maps. It has one controller which reads as follows:

class RequestsController < ApplicationController layout "default" active_scaffold end

Through the power of ActiveScaffold my app is up and running, and within a stones-throw of being finished

ActiveScaffold gives me all of the CRUD forms that I need for my little application. The screen shot is of the edit form for an existing record. It has the master-detail relationship from my request model to my item model, it has the selectors for my lookup tables for status, user, and project, and it even has the ability to add rows to my lookup tables on the fly.

It’s not perfect, but it is already very useful. There is an extension mechanism so that I can add the functionality to upload an image and store it in the DB — which is the next task for me to implement. Let me re-phrase that…the functionality to upload the image is the first real code I’ll need to write for this app (grin)


By the way, if you haven’t taken time to fill out our Ruby and Ruby on Rails survey we’d really like your input. The survey is here: http://www.surveymonkey.com/s.asp?u=187863298831

Technorati Profile

Add to Technorati Favorites

Posted by Joe McGlynn on March 14th, 2007 under Ruby and Rails |



4 Responses to “Rails Scaffolding”

  1. Cody Skidmore Says:

    >We collect everyone’s needs and then work with

    >a graphics artist to get the images composed

    >and reviewed

    Can I borrow the graphics artist? That gene escaped my DNA. Actually, is it possible to be a good software developer and also a good graphics artist? Hmm.

    Just a note: Dynamic scaffolding was recently removed from Rails. It was moved to a plug-in so it is still available.

  2. Joe McGlynn Says:

    >> Actually, is it possible to be a good software developer and also a good graphics artist? Hmm.

    Probably, in my experience good engineers have other creative outlets — like music, building furniture and so forth.

    I have to agree, at face value it seems unlikely.

  3. . Says:

    You might like Streamlined http://www.streamlinedframework.org/

  4. chipcastle Says:

    I’m using AS and love it. Your example is excellent, but I was wondering how you overrode your templates and combined your models in the subform. Any code examples would be appreciated. Thanks.



Server Response from: blogs2.codegear.com