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: Books, Tutorials, Fixes, RubyOnRails
Feedback