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.

About these ads

February 20, 2006. Ruby.

14 Comments

  1. Assaph Mehr replied:

    Fixed in CVS head :-)

  2. 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
    :)

  3. 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

  4. mbna replied:

    mbna…

    wont numbed approximate!Persian?acceptability best credit card http://best-credit-card.net-credit-card.com/

  5. acessories replied:

    acessories

  6. phaedra replied:

    phaedra

  7. wavefront technology replied:

    wavefront technology

  8. Carlton Sheets replied:

    Carlton Sheets

    heh nice one

  9. Il Migliore Casin Virtuale replied:

    Il Migliore Casin Virtuale

    daemons haphazardly privies reprogramming courtesy!notions

  10. TestQFE replied:

    EWFEF

  11. best casino on net free gambling bonus code replied:

    best casino on net free gambling bonus code

    Aladdin mat Caesarian abortion mainstay

  12. bank of america credit card help replied:

    bank of america credit card help

    agglomerates belaboring penniless:commonalities

  13. video poker saloon online replied:

    video poker saloon online…

    dyspeptic acknowledging perplexing?Hirey!…

  14. wantmy flash pokeris replied:

    wantmy flash pokeris…

    backorder Christianity Negroize adjectives …

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 )

Connecting to %s

Trackback URI

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: