small medium large xlarge

_mg_8864 - cropped square_pragsmall
20 Nov 2011, 05:52
Jeremy Ross (5 posts)

When running tests, I get:

test_should_create_line_item undefined method `price=' for #<LineItem:0x007fdbdb7893d0>
app/models/cart.rb:18:in `add_product'
app/controllers/line_items_controller.rb:53:in `create'

cart.rb add_product() expects line_item to have a price attribute:

current_item.price = current_item.product.price

I can’t find where we added price to line_item. Can someone please point me to where I can find this in book version 2.1?

Thanks

Samr_small_pragsmall
20 Nov 2011, 14:46
Sam Ruby (634 posts)

Can someone please point me to where I can find this in book version 2.1?</blockquote>

First “Playtime” exercise at the end of chapter 10. These exercises are optional, but solutions to selected ones (including this one) are included in the downloadable code. You can find hints (as well as follow the link to the solution in this case) on the wiki:

http://pragprog.com/wikis/wiki/Task-E-ASmarterCart
_mg_8864 - cropped square_pragsmall
20 Nov 2011, 17:09
Jeremy Ross (5 posts)

Thanks. I also assumed I could, at any point, “reset” to the downloadable code. I think I tried depot_n and depot_r. Neither had the price column, yet cart.rb expects it.

Samr_small_pragsmall
20 Nov 2011, 20:14
Sam Ruby (634 posts)

depot_n (and depot_r) have the migration that is used to add price to line item:

http://media.pragprog.com/titles/rails4/code/rails31/depot_n/db/migrate/20110711000006_add_price_to_line_item.rb

You must be logged in to comment