Written by: steve ross on February 26th 2008

911 The Depot App in AWDROR Won't Work Without Scaffolding!

As of Rails 2.0, the deprecation warnings came out and so did a number of features present in earlier versions. One of the greatest pain points has been the removal of dynamic scaffolding. There have been some extensive discussions on the Rails mailing list regarding the removal of scaffolding (other threads exist as well).

I want to be completely clear that scaffolding still exists in Rails as a one-shot generator. If you create a migration, run it, then generate a scaffold, you will be rewarded with a proper RESTful chunk of generated code in the expected places. What is now missing is the ability to define a controller class thusly:

  
    class PeopleController
      scaffold :person
    end
  

It's gone, extracted to its own plugin. Bear with me while I break the discussion down a bit further, then I promise to give you the short solution.

There have been several central themes, as far as I can tell:

In a world devoid of alternative solutions I would agree with these points and also with the comment made on the mailing list that the Rails core team was "out of touch." But there are tons of alternatives and nothing really went away. I'll get to that later. First, cut to the chase.

How To Get Depot Back On the Rails

Follow along in the book and where they say to type rails depot, don't. Instead, type:

$ rails depot --database=mysql

The reason for this is that the new Rails default database is SQLite instead of MySQL. Personally, I think this was a good decision because even though it wasn't a big deal, creating 3 MySQL databases and then remembering to blow them away was a PITA when I was just creating a project to test assumptions. With SQLite, when I do a rm -rf depot, everything including my dev and test database vaporizes.

Next, remember how I said none of the functionality was gone, it was simply extracted? Well, let's plug it back in.

Do this:

  
    cd depot
    ruby script/plugin install scaffolding
    ruby script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination
  

Note: This last bit installs the Rails pagination code which scaffolding's list action relies on.

At this point, you should be ready to continue on with the Depot tutorial.

For Your Consideration

In days gone by, we relied on a "vendor" to supply us all the system-level plumbing we needed as we developed applications. I was stunned when I started looking at Rails and discovered there was such a nicely formed framework with no thought given to authentication. This, I was sure, was such a commonly performed implementation detail that there had to be a standard Rails way to get users logged in. Right? Wrong. Several different authentication thingies were floating around, complete with the authors' caveats that they knew there was cruft in their solution or your needs might vary. Now there a numerous different authentication solutions ranging from model-based to role-based to RESTful, and lots of others. See, there really isn't a one-size-fits-all authentication solution.

Why is this even remotely relevant? Because where a feature was perceived as useful, people made it available as open source and you could judge it on its merits. The same goes for scaffolding and pagination. Rails scaffolding and pagination have been the punching bags of the codebase for a long while, and people only miss them now that they're gone.

I would encourage you to finish your Depot application, learn to love Rails, but also to consider what you might choose as alternatives for scaffolding and pagination.

A few I would point to are:

ActiveScaffold
will_paginate
paginating_find