Home > ColdFusion, Web Application Development > Scaffold Plugin for CFWheels

Scaffold Plugin for CFWheels

Once upon a time I dabbled in Ruby on Rails(RoR) and I remember the coolest thing, or so I thought, was scaffolding.  This is the process whereby the framework looks at your db tables to create simple CRUD forms and CFCs.  The generated code was almost never useful, but it got some of the mundane tasks out of the way and served as a starting point.

I was pleased when listening to Mike Henke’s talk on the Online Coldfusion Meetup last week, I heard about the Scaffold plugin, built by Raul Riera.  I decided to put it to the test for an application at work that is also serving as my means of learning CFWheels.  Using the plugin is quite simple.

  1. Download the plugin
  2. Copy the zip file to the plugins directory in your application.
  3. Reload your application by adding ?reload=true in the querystring

In the debugging output of your application, assuming you’re running in development mode, you should now see Scaffold in the Plugins section as a link.

CFWheels debug output

CFWheels debug output

Clicking the Scaffold link takes the user to a page for the plugin.  This is where the magic happens.  Enter the object name.  This must correspond to a table in your database.  Next, tell the plugin what you want to create, in this case we want the Model, View, and Controller.  Select how you want your CFCs coded–I  tend to use default, but you can use CF8 script or CF9 script. Click Generate and let it do it’s thing for a few seconds.  Then check your Controllers folder, you should have your new [controller].cfc.  Same for the models folder.  In your Views folder, you should notice index, edit, new, and show view files.  Index.cfm lists all records, while show displays a single record.  The others should be self-explanatory.  Try creating a new record and your data should be inserted correctly.  Pretty slick.

It’s that simple.  In my past I would always start a project out by creating the CRUD in my CFCs.  It’s a simple task, but also a time-consuming task.   Of course I also had much more complex queries and business logic to write in my CFCs.  Having a scaffold create the basics would have allowed me to start the more complex stuff sooner.  As I said before, the generated files are almost never totally useful by themselves, but they do provide a great starting point and allow you to start the real work of solving problems sooner.

  1. August 17, 2010 at 3:33 pm

    Sweet post! there are some minor upgrades to this plugin at github, nothing too fancy though, just small “gotchas”

    – Compatibility with Wheels 1.0.5.
    – Made the “default” template appear at the top of the select box.
    – Updated the docs to reflect why the flash messages are not used in the views.


    • August 17, 2010 at 3:37 pm

      Actually, it is on the site, so…. nevermind me.. I am nuts 😛

  1. January 2, 2011 at 2:43 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: