UPDATE: this issue is addressed in “this forum post”:http://forums.pragprog.com/forums/66/topics/8971
I am having trouble with the first playtime challenge for Task E:
a migration that copies the product price into the line item, and change the add_product method in the Cart model to capture the price whenever a new line item is created.
I created a migration with the following code, but keep getting “undefined method `price’ for nil:NilClass” when I run the the migration using rake.
class AddPriceToLineItem < ActiveRecord::Migration def change add_column :line_items, :price, :decimal LineItem.all.each do |li| li.price = li.product.price end end def self.down remove_column :line_items, :price end end
</code> The issue is somewhat addressed in “this forum posting”:http://forums.pragprog.com/posts/search?utf8=%E2%9C%93&q=product+price , but not really. In the playtime wiki for this challenge a link is provided to the “Author’s solution”:http://intertwingly.net/projects/AWDwR4/checkdepot-188-30/section-10.4.html (at bottom of page - what I based my migration code on), but it does not work.
Can someone suggest an updated or correct approach? Many thanks.