# "Undefined method" problem in "Agile Web Development With Ra

**URL:** <https://www.ruby-forum.com/t/undefined-method-problem-in-agile-web-development-with-ra/54457>\
**Category:** Rails\
**Created:** [March 5, 2006, 9:34pm UTC](https://www.ruby-forum.com/t/undefined-method-problem-in-agile-web-development-with-ra/54457 "2006-03-05T21:34:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emil\_Gustafsson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/edb3f5/32.png) [@Emil\_Gustafsson](https://www.ruby-forum.com/u/Emil_Gustafsson)\
**Post date:** [March 5, 2006, 9:34pm UTC](https://www.ruby-forum.com/t/undefined-method-problem-in-agile-web-development-with-ra/54457/1 "2006-03-05T21:34:36Z")

</div>

Hi,

I’m reading the “Agile Web D. With Rails” book. So long,  
everything has worked fine, but now I got this annoying error message  
that I just can’t understand. The error appears for me around page  
87, chapter 8.

NoMethodError in Store#display\_cart

Showing app/views/store/display\_cart.rhtml where line #28 raised:

undefined method `product’ for 2395.0:Float

Extracted source (around line #28):

25:   
26: \<%  
27: for item in @items  
28: product = item.product  
29: -%\>  
30:

  
31: \<%= h(product.title) %\>

I’m sure my source code is correct.

//Emil

---

<div class="post-metadata">

**Author:** ![Emil\_Gustafsson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/edb3f5/32.png) [@Emil\_Gustafsson](https://www.ruby-forum.com/u/Emil_Gustafsson)\
**Post date:** [March 5, 2006, 9:43pm UTC](https://www.ruby-forum.com/t/undefined-method-problem-in-agile-web-development-with-ra/54457/2 "2006-03-05T21:43:47Z")

</div>

For some reason your object “item” has the value 2395.0, and is a  
floating point object. Without having the Agile book at my  
fingertips, from memory it’s supposed to have a price attribute with  
that value.

At a guess, you could be setting @items to an individual item, rather  
than a collection of items. That would be consistent with the error  
you’re seeing.

Have a look at your controller code where you set @items to something;  
the problem’s probably going to be right around there.

HTH

Dave M.

---

<div class="post-metadata">

**Author:** ![Emil\_Gustafsson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/edb3f5/32.png) [@Emil\_Gustafsson](https://www.ruby-forum.com/u/Emil_Gustafsson)\
**Post date:** [March 5, 2006, 10:50pm UTC](https://www.ruby-forum.com/t/undefined-method-problem-in-agile-web-development-with-ra/54457/3 "2006-03-05T22:50:17Z")

</div>

This is the code in the controller where @items is set:

def display\_cart  
@cart = find\_cart  
@items = @cart.items  
end

private  
def find\_cart  
session[:cart] ||= Cart.new  
end

And this is the code in the cart.rb model:

class Cart

attr\_reader :items  
attr\_reader :total\_price

def initialize  
@items = []  
@total\_price = 0.0  
end

def add\_product(product)  
@items \<\< LineItem.for\_product(product)  
@total\_price += product.price  
end  
end

Any idea?

5 mar 2006 kl. 21.43 - 5 mar skrev David M.:

> the problem’s probably going to be right around there.
> 
> > has worked fine, but now I got this annoying error message that I
> > 
> > 31: \<%= h(product.title) %\>
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Hälsningar,  
Emil

removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Emil\_Gustafsson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/edb3f5/32.png) [@Emil\_Gustafsson](https://www.ruby-forum.com/u/Emil_Gustafsson)\
**Post date:** [March 22, 2006, 5:39am UTC](https://www.ruby-forum.com/t/undefined-method-problem-in-agile-web-development-with-ra/54457/4 "2006-03-22T05:39:56Z")

</div>

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.
