Chapter 6 (continued)
Ok. Back to work.
Page 61. I need to add another column to my table. I’m going to do something similar to what the book does: alter the script I have that creates the table, although KirbyBase does have an #add_column method that would work also.
So, I open up db/development/create_db.rb. I need to add a column called “date_available”. The column type is datetime. No problem, KirbyBase has a DateTime column type. Here’s what the modified line in the script now looks like:
db.create_table(:products, :title, :String,:description, :String, :image_url, :String,:price, :Float, :date_available, :DateTime)
Now, I just execute the create_db.rb script again to recreate the table.
Page 62. I run the command to regenerate the Admin scaffolding.
Page 63. I refresh the browser and find myself back at the “Listing Products” screen. I click on “New product”. I notice that the “Date Available” field shows up a the bottom of the screen. So far so good. I enter a new record, leaving the default date of today, and click “Create”. Uh, oh. Another full-screen error. It is telling me that there is invalid data in the “date_available” field. The trace goes back to the #validate_input method in KirbyBase. Obviously, the data that Rails is passing back to KirbyBase is not a DateTime. I throw a couple of debugging “puts” in kirbybase.rb and rerun. It turns out that Rails is trying to save a Time object in the date_available field, and, since KirbyBase has it defined as a DateTime, it throws up.
Well, I will need to send this off to Assaph to see if Rails is supposed to be interpreting a KirbyBase DateTime field type as a Time field type. In the meantime, a quick fix is to simply change the field type in my KirbyBase table to Time. It will work just as well for this exercise. So, I open up create_db.rb again and change DateTime to Time. Re-execute create_db.rb. Rerun the Admin scaffolding. Click “New product” again. Oops! Where’s the “Date Available” field? The “Date Available” label shows on the form, but there is no form field. This looks like another issue. It appears that Rails does not know how to render an input field for a KirbyBase :Time field. So, I send this info off to Assaph in an email.
Now, how do I temporarily work around this issue so I can keep going. I’ve got it. First of all, I change the “Date Available” field type in my table back to DateTime. Next I regenerate the scaffolding. This will make sure that Rails creates a form field for “Date Available”. But, Rails is going to pass back a Time field to KirbyBase and KirbyBase is expecting a DateTime. Ok, I open up my KirbyBase table in a text editor and change the field type for “Date Available” back to :Time. Now, I make sure not to regenerate the scaffolding. Now, go back to the “Listing Products” screen. Click on “New product”. Fill in the info. Click on “Create”. Bingo! It works. My new record is staring me in the face, including the “Date Available” data.
Whew! I’m tired again. Blogging is tough work. I’m going to bed.
Assaph Mehr replied:
Fixed in CVS head :-)
February 20, 2006 at 12:49 pm. Permalink.
Tony Patterson replied:
Hi,
I can’t seem to find or view your entry for the start of Chapter 6. Is it up somewhere?
Thanks
Tony
:)
February 21, 2006 at 12:45 am. Permalink.
houseonfire replied:
Hey, Tony. It should be right below the Chapter 6 (continued) entry. If I scroll down it shows up right below. It should be titled “Chapter 6″. Does it not show up for you?
I am blogging newbie, so I am at a loss for why it does not show up for you.
Jamey
February 21, 2006 at 1:39 am. Permalink.
mbna replied:
mbna…
wont numbed approximate!Persian?acceptability best credit card http://best-credit-card.net-credit-card.com/ …
May 21, 2006 at 5:09 pm. Permalink.
acessories replied:
acessories
October 13, 2006 at 4:31 am. Permalink.
phaedra replied:
phaedra
October 15, 2006 at 2:06 am. Permalink.
wavefront technology replied:
wavefront technology
October 16, 2006 at 10:33 pm. Permalink.
Carlton Sheets replied:
Carlton Sheets
heh nice one
December 29, 2006 at 11:22 pm. Permalink.
Il Migliore Casin Virtuale replied:
Il Migliore Casin Virtuale
daemons haphazardly privies reprogramming courtesy!notions
May 1, 2007 at 11:10 am. Permalink.
TestQFE replied:
EWFEF
July 12, 2007 at 10:58 pm. Permalink.
best casino on net free gambling bonus code replied:
best casino on net free gambling bonus code
Aladdin mat Caesarian abortion mainstay
October 26, 2007 at 12:37 am. Permalink.
bank of america credit card help replied:
bank of america credit card help
agglomerates belaboring penniless:commonalities
November 1, 2007 at 3:54 pm. Permalink.
video poker saloon online replied:
video poker saloon online…
dyspeptic acknowledging perplexing?Hirey!…
July 20, 2008 at 10:07 am. Permalink.
wantmy flash pokeris replied:
wantmy flash pokeris…
backorder Christianity Negroize adjectives …
January 23, 2009 at 6:47 pm. Permalink.