small medium large xlarge

16 Sep 2008, 11:50
Tate (5 posts)

I started reading through the book this past weekend and have managed to make some good progress, but now I’m stuck. I’m on page 154, trying to place orders but I get this issue. I’ve compared my code w/ the book and example code with no luck. It gives the following complaint:

ActiveRecord::AssociationTypeMismatch in StoreController#save_order

LineItem(#20308640) expected, got BigDecimal(#8473270)


app/models/order.rb:16:in `add_line_items_from_cart'
app/models/order.rb:14:in `each'
app/models/order.rb:14:in `add_line_items_from_cart'
app/controllers/store_controller.rb:35:in `save_order'

I fail to see whats wrong w/ the save_order action or whats wrong in the order model - I’ve replaced both with the example code and get the same issue. What could I be missing?

16 Sep 2008, 14:54
Sam Ruby (634 posts)

The last line of self.from_cart_item in app/models/line_item.rb is supposed to read “li”. By any chance, is this line missing?

16 Sep 2008, 15:30
Tate (5 posts)

I don’t have the code in front of me but I think you’re right - its missing. I’ll give that a try in a bit, thanks Sam

15 Feb 2009, 22:28
Jerome Ripley (1 post)

Without the last li I get the same error. With the li line it works. What is the use of the last li in? def self.from_cart_item(cart_item) li = li.product = cart_item.product li.quantity = cart_item.quantity li.total_price = cart_item.price li end

25 Feb 2009, 00:25
Charles Curley (3 posts)

If Ruby is like Perl or shell scripts, then the last thing evaluated is the return value. So having the li in there forces the method to return it.

Just a guess from an RoR illiterate.

19 May 2009, 17:18
Omar Shaat (3 posts)

li is the object being returned from the method which is used in another method in the application

19 Dec 2009, 04:25
Brian Heideman (1 post)

Wow, two characters. Thanks Sam. I’ve been racking my eyeballs for an hour and a half. Completely missed that.

You must be logged in to comment