Conclusion of Chapter 6
Ok, I’m going to cheat a little bit. :)
I’m going to go to RubyForge and grab the latest version of Ackbar in CVS. The reason for this is because Assaph already has put in a fix for the DateTime issue I had in my last post. Also, he has a fix in for an error that I haven’t mentioned yet: when I would click on “edit” for an existing record on my “Listing products” page, I would get a full screen error stating, “Expecting a list of IDs!”.
Anyway, both of these errors, and the error I posted about a couple of days ago have all been fixed in CVS head, so grab it if you are following along.
Back to Chapter 6. Page 64. I add the validates_presence_of code to the Product class. Switch over to my browser and try to add a new, empty record. I get the three validation errors. Great! I enter data into the fields and click “Create” again. This time Rails adds the new record.
Page 65. I open up the Product class again to add the validates_numericality_of code for :price. I test this and do indeed get an error message when trying to save alphabetic characters in the :price field.
Page 66. I add the validate method in class Product to check for a positive number in :price. I test this and it gives me an error when I attempt to save -123 in :price.
Page 66. I add in the last two validations: uniqueness of :title and format of :image_url. I test for both and they throw errors as expected.
Were making good progress!
Page 67. I make all of the changes to list.rhtml and scaffold.css. I put some images in public images. I switch over to my browser and reload admin/list. Everything looks great.
I click on “Destroy” for one of the records, and the record is deleted. I edit the description of a record, and do a “cat products.tbl” to make sure it is reflected in the database.
By the way, here’s another reason why Ackbar/KirbyBase might be attractive to you. Since KirbyBase tables are simply text files, it’s very easy to open them up and make sure changes you make in a Rails app are properly reflected in the database.
Alright. I’m done with Chapter 6 and, besides a few minor glitches that Assaph has already fixed, Ackbar/KirbyBase passed the test.
On to Chapter 7!