Re:

From: Josh K. <[email protected]…>
Subject: Re: “Undefined method” problem in "Agile Web D. Wit
Newsgroups: gmane.comp.lang.ruby.rails
Date: 2006-03-22 04:39:56 GMT (19 weeks, 4 days, 23 hours and 8 minutes ago)

I am working through that book as well. I am getting the exact same
error. I thought it was something I did wrong but I have no idea what to
check since I’m still pretty new at this stuff.

Hopefully, it’s the syntax of the book. Has anyone seen the errata or
have any ideas? I would think that if we’re getting the same results,
surely there’s someone else out there who knows what’s going on.

I had similar problems, turns out in the method LineItem#for_product the
last
line for me was “item.unit_price = product.price”, so this was returning
the
float rather than the “item” object itself.
All you need is to add a line “item” which would return the object
rather than
the float -

class LineItem < ActiveRecord::Base
belongs_to :product

def LineItem.for_product(product)
item = self.new
item.quantity = 1
item.product = product
item.unit_price = product.price
item #### <- This was missing when i got the error
end
end

HTH
Nasir

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs