small medium large xlarge

11 Feb 2012, 19:01
Joseph Venator (3 posts)

UPDATE: this issue is addressed in “this forum post”:

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
  def self.down
    remove_column :line_items, :price

</code> The issue is somewhat addressed in “this forum posting”: , but not really. In the playtime wiki for this challenge a link is provided to the “Author’s solution”: (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.

You must be logged in to comment