I’m a Richardson, RU?

01 Oct, 2006

Agile Web Development with Rails Code Fix

Posted by: imarichardson In: Apple/Macintosh| Books & Publications| Programming & Development

If anyone is going along through the Agile Web Development with Rails book and gets to page 66 where you are using the migration “alter table products …” you’ll indubitably come across the error where Rails doesn’t seem to like what you’ve put in the migration file. You may receive an error like:

AddPrice: migrating ===================================================== —add_column(:products, :price, :decimal, {:precision=>8, :default=>0, :scale=>2}) rake aborted! You have a nil object when you didn’t expect it! You might have \expected an instance of Array. \The error occured while evaluating nil. (See full trace by running task with—trace)

I found this post which helps out. It looks like the problem is with the decimal type specified so instead of what the book gives, type this as you’re migration and everything should work without a hitch:

class AddPrice < ActiveRecord::Migration def self.up add_column :products,:price,:integer,:precision => 8,:scale => 2,:default => 0 end def self.down remove_column :products, :price end end

So it’s not really a fix and t doesn’t solve the fact that you don’t have a decimal, but at least it will let you move on through the book (and I still can’t figure out why it won’t work, even with rails “on the edge” working)…

Technorati Tags: , , ,

No Responses to "Agile Web Development with Rails Code Fix"

Comment Form

You must be logged in to post a comment.

I'mARichardson Who?

Who am I? Well, let's see: I'm a husband, father, brother, God-father, down to earth, relaxed, happy kinda guy who likes clean code, long walks on the beach, takes his laptop with him everywhere he goes, and (as I'd like to think) all around good guy!