Chapter 8

There is not a lot to blog about this chapter, since there isn’t very much database interaction in it. It gets a little more interesting from an Ackbar/KirbyBase perspective in Chapter 9. But, here goes anyway…

Page 81. In order to create the line_items table, I’m going to open up the create_db.rb script and add the following lines:

db.drop_table(:line_items) if db.table_exists?(:line_items)
db.create_table(:line_items,
 :product_id, :Integer,
 :quantity, {:DataType => :Integer, :Default => 0},
 :unit_price, :Float)

Now, there are a couple of interesting things here. One is that, unlike the book, I don’t need to specify an “id” field for the line_items table. KirbyBase automatically creates an auto-incrementing, primary key field for each table called :recno. Assaph, in Ackbar, maps the :recno field to a field called “id”, so that Rails is happy.

The second thing to point out is that you can specify default values for KirbyBase columns, as we do here for the :quantity field. Because we are specifying additional info for this field, we have to put the info, including the field type in a hash, so that KirbyBase knows that all of that info applies to the :quantity field.

Now I simply execute create_db.rb again to recreate all of the tables.

The rest of the chapter deals primarily with creating the cart model, which isn’t an actual database table.

The good news is I am able to complete the chapter using Ackbar/KirbyBase and everything works. I’m on to Chapter 9.

About these ads

February 22, 2006. Ruby.

One Comment

  1. 傘 バーバリー replied:

    彼女は夏のために単純に完璧になるおむつ袋を持っている

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: