Home > CFWheels, ColdFusion > CFWheels Scaffolding Basics

CFWheels Scaffolding Basics

August 11th, 2009

I choose CFWheels as my first ColdFusion framework to learn. I was going to learn ColdBox, but quickly discovered that I would really have to learn Transfer or Reactor and Coldspring at the same time. These may be good tools, but I wanted to focus mostly on mastering the Model View Controller pattern.

I’ve been really pleased with CFWheels. It’s the ColdFusion answer to Ruby on Rails, and it just makes sense to me!

The documentation is good. Still, for a new learner, some things are missing. So, I thought maybe I can leverage some Rails resources. I found a great book — Head First Rails. I’m going to do some posts on translating the book to CFML and to CFWheels. I think this will help my learning and may help others.

From here, I’m assuming that you know something about web development, CFML, and already have a ColdFusion server running on your computer. If not, this information may be too advanced for you. CFWheels runs great on the development edition of ColdFusion that’s available from Adobe. Railo is also supported. You can learn more about the requirements at: http://cfwheels.org/docs/chapter/requirements.

Now on to Head First Rails, Chapter 1: Really Rapid CFWheels

Page 7: Creating a New Application

In Rails, you open a command prompt and type > rails tickets.  This sets up the folder structure for your app.

In CFWheels, you do the same thing by downloading the CFWheels files and just unzipping them to a folder named tickets in your webroot. The name of the folder is very important. CFWheels and Rails both rely on convention instead of configuration. Things have to be named consistently!

Page 14: Creating Tables (Migration)

In Rails, you create tables in the database by going to a command prompt and typing > ruby script/generate scaffold tickets … Then, you have to run a migration by typing > rake db.migrate. These two commands also write code for your application! Rails will automatically create Model, View, and Controller files for your new table.

CFWheels handles this a little differently, but you can quickly get to the same place. First, you have to install the Scaffolding plugin.

  • Download the scaffolding plugin
  • Save the .zip file in your wwwroot/tickets/plugins folder.
  • Reload CFWheels by running this URL in your browser: http://localhost/tickets/?reload=true
  • CFWheels will automatically unzip and install the file! You’ll see Scaffold listed as a plugin at the bottom of the page along with other debugging information.
  • NOTE: Apparently there’s a problem with the Plugin Manager right now. I had to delete the Plugin Manager files from the plugins directory. Then, this process worked for me. I discovered the problem was with my ColdFusion server configuration. I had added a Dump() method to Component.cfc. When Wheels tried to load multiple plug-ins, it saw the duplicated method, and threw an error as a result of the naming conflict.

You’ll only need to do the steps above once. Now, lets use scaffolding to create an app in CFWheels. Instead of using the script/generate syntax, CFWheels expects you to just create your table via a SQL query or whatever database tools you like to use. Most developers know how to do this, and I like this approach better than learning a new syntax in Rails!

Here’s my Create Table SQL script. This is essentially the same command you type into Rails via script/generate.

CREATE TABLE `tickets` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`seat_id_seq` varchar(255) NOT NULL,
`address` text NOT NULL,
`price_paid` decimal NOT NULL,
`email_address` varchar(255) DEFAULT NULL,
PRIMARY KEY  (`id`)
)

Now, it get’s really easy. Either click the Scaffold link on the bottom of your browser screen, or point your browser to http://localhost/tickets/index.cfm?controller=wheels&action=plugins&name=scaffold. This will display the scaffolding plugin screen.

Just enter the name of the table and click Generate. That’s it! Instant Application. Go to  http://localhost/tickets/index.cfm?controller=tickets&action=index to see your new application. Rails automatically creates a route, so their URL is simpler, and you can easily do the same thing if you want. For me, when learning, I’d rather see the controller and action clearly shown in the URL. There’s always time to switch to pretty URL’s later on.

Next we’ll edit the HTML in the view. But, that’s another post. Please leave a comment if I got something wrong or you like my approach!

Clarke Bishop CFWheels, ColdFusion

  1. August 11th, 2009 at 09:27 | #1

    Awesome. I will definitely link this from the Community page on cfwheels.org.

    There are some things we do differently, but that’s mainly because we’re much newer (and smaller) than Rails. As a result, we’ve had to prioritize what to work on, which mainly has been a framework that does 80% of what you want to do, with good performance.

    I’m not sure that the Plugin Manager is broken for _everyone_ as we haven’t really heard any complaints about it. Can you give us more specifics about your environment on the list? CFML engine? Wheels version? Web server?

  2. Sam Singer
    August 11th, 2009 at 09:33 | #2

    Clark,
    I tried CFWheels awhile back. I liked it, but seems that I ran into some problems getting it to work with our server configuration. It also seemed that the project’s development had stalled. Maybe the later parts of the documentation were a little incomplete. If you find that it’s working for you, I’ll give it another shot. I like Ruby on Rails and have been working with it a little recently. Good luck.
    Sam Singer

  3. August 14th, 2009 at 18:41 | #3

    Do you need to use your path to the scaffolding or can I use http://localhost/index.cfm/wheels/plugins?name=scaffold

  4. Clarke Bishop
    August 16th, 2009 at 12:45 | #4

    The long link I had in my post, http://localhost/tickets/index.cfm?controller=wheels&action=plugins&name=scaffold is the link that’s listed at the bottom of each page with the rest of the debugging information. I tried your suggestion, and it didn’t work for me — Probably because I am using the development version of ColdFusion and URL rewriting isn’t turned on!
    I think the link I suggested is the safest one, but I’m sure there are other possiblities.

  5. August 16th, 2009 at 17:24 | #5

    @Sam: Why have you said the development has stalled? I have seen it non stop for over a year now/

  6. August 16th, 2009 at 20:09 | #6

    I tried http://localhost/index.cfm/wheels/plugins?name=scaffold for my setup and it loaded fine but didn’t work when submitting.

  7. August 19th, 2009 at 10:29 | #7

    Clarke,

    When I got involved with the CFWheels project almost two years ago one of my goals was to take a Rails book and translate the examples in the book to Wheels. But of coarse life got in the way and that task is still on my to do list. I’m glad that someone else has picked up the baton and is running with it. Great job and keep the posts coming.

  8. September 9th, 2009 at 13:54 | #8

    I’m not sure why you say that you “really have to learn Transfer or Reactor and Coldspring at the same time” if you want to learn ColdBox. I’ve been using ColdBox for the last couple of years and haven’t done a single thing with Reactor or Transfer. Also, you COULD use ColdSpring but you don’t have to (specially with the built-in IOC, AOP, and remote proxying capabilities built in to ColdBox). I could understand that if ORM is one of your requirements why you made that statement (and why you chose CFWheels since it has ORM built in). But not everyone wants or needs ORM.
    Of course, I’m happy for you that CFWheels is working out for you. But that statement about ColdBox was very misleading, IMHO.

  9. Clarke Bishop
    September 9th, 2009 at 14:05 | #9

    It’s probably just my ignorance of ColdBox showing up. Several of the examples I saw seemed to rely on Reactor & Coldspring.

    From what I can tell ColdBox is very powerful — In fact, it was too much for me. CFWheels has been a great fit and I’ve been able to get down the MVC learning curve more easily.

    Thanks for your clarification on ColdBox!

  10. November 17th, 2009 at 07:40 | #10

    FYI, the PluginManager has been updated and can be downloaded here:
    http://cfwheels.org/plugins/listing/8

    I’ll be updating it again here soon too. The biggest thing that I want to add is a version comparison that shows an “Upgrade” link when an update is available.

  11. Sam Singer
    February 12th, 2010 at 17:37 | #11

    @Raul Riera
    Hello Raul,
    I started using cfwheels more than 2 years ago. That’s when I experienced the seemingly stalled development and incomplete docs. Today it’s terrific! Coding is Good!

  12. Clarke Bishop
    February 12th, 2010 at 18:35 | #12

    I’ve just been adding some custom tags to the Splash CMS that runs on top of CFWheels.

    As impressive as CFWheels and its documentation have become, I still didn’t realize how powerful CFWheels can be. It took me a while to figure out how to use ColdFusion custom tags effectively. But, on the Wheels side, every time I need a piece of data or a function to access the data, it was already there for me.

    Its like CFWheels knew what I was going to want before I did. Amazing!

  1. No trackbacks yet.