In Part 2, we looked at Editing the View in CFWheels.
We thought we were done, but now the boss wants to record events along with ticket sales. Remember we are following along in Head First Rails, and converting everything to CFWheels!
Fortunately, with scaffolding, all we need to do is create the new database table and run the scaffolding plugin.
Here’s the create table SQL query:
CREATE TABLE `events` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`artist` VARCHAR(255) NOT NULL,
`price_low` DECIMAL NOT NULL,
`price_high` DECIMAL NOT NULL,
`event_date` DATE NOT NULL,
PRIMARY KEY (`id`)
I got the idea from a Rails app to create a “spec” directory to hold application specification information. And, I created a database sub-directory to hold all my table creation SQL. So the query is stored in /spec/database/events.sql.
Next, click the Scaffold link. Look in the debug information at the bottom of each page, next to Plugins. Then, on the scaffold page, enter event as the Object name, and click Generate. Remember, the table is named events (plural with an “s”), but the the object is named event (singular).
All that’s left is to open /views/events/ and edit the labels in edit.cfm, index.cfm, new.cfm and show.cfm. This last step isn’t really needed to make things work, but the boss is kind of picky.
Great — We’ve finished with Chapter 1 of Head First Rails. You now know how to:
- Create a new CFWheels application
- Install the scaffolding plugin to CFWheels
- Setup a database table and use scaffolding to automatically generate the Model, View, and Controller code.
- Edit HTML in the View
- Add fields and new tables to the database
Next time, we’ll start Chapter 2, and build an application from scratch — Without using scaffolding.