# Having Problem w/ Agile Web Development book

**URL:** <https://www.ruby-forum.com/t/having-problem-w-agile-web-development-book/101620>\
**Category:** Rails\
**Created:** [August 6, 2006, 8:45pm UTC](https://www.ruby-forum.com/t/having-problem-w-agile-web-development-book/101620 "2006-08-06T20:45:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![necrocyte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@necrocyte](https://www.ruby-forum.com/u/necrocyte)\
**Post date:** [August 6, 2006, 8:45pm UTC](https://www.ruby-forum.com/t/having-problem-w-agile-web-development-book/101620/1 "2006-08-06T20:45:00Z")

</div>

I get this error …

NoMethodError in StoreController#index  
undefined method `salable\_items’ for Product:Class

and here is my store\_controller.rb …

class StoreController \< ApplicationController

def index  
@products = Product.salable\_items  
end

def self.salable\_items  
find(:all, :conditions =\> “date\_available \<= now()”, :order =\>  
“date\_available desc”)  
end  
end

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![necrocyte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@necrocyte](https://www.ruby-forum.com/u/necrocyte)\
**Post date:** [August 6, 2006, 8:50pm UTC](https://www.ruby-forum.com/t/having-problem-w-agile-web-development-book/101620/2 "2006-08-06T20:50:15Z")

</div>

On 06 Aug 2006, at 20:45, Chad Saunders wrote:

> class StoreController \< ApplicationController  
> […]  
> def self.salable\_items  
> find(:all, :conditions =\> “date\_available \<= now()”, :order =\>  
> “date\_available desc”)  
> end  
> end

Define self.salable\_items in your Product class, not your  
StoreController class.

Regards,

Denis D.

–  
mail: removed\_email\_address@domain.invalid  
web: [http://stoneship.org/](http://stoneship.org/)

---

<div class="post-metadata">

**Author:** ![necrocyte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@necrocyte](https://www.ruby-forum.com/u/necrocyte)\
**Post date:** [August 6, 2006, 8:50pm UTC](https://www.ruby-forum.com/t/having-problem-w-agile-web-development-book/101620/3 "2006-08-06T20:50:16Z")

</div>

Chad Saunders wrote:

> ```
> @products = Product.salable_items
> 
> ```

salable\_items are defined in the StoreController class, not in the  
Product class.

–  
Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
JvYAML, RbYAML, JRuby and Jatha contributor  
System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))

“Yields falsehood when quined” yields falsehood when quined.

---

<div class="post-metadata">

**Author:** ![necrocyte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@necrocyte](https://www.ruby-forum.com/u/necrocyte)\
**Post date:** [August 6, 2006, 9:29pm UTC](https://www.ruby-forum.com/t/having-problem-w-agile-web-development-book/101620/4 "2006-08-06T21:29:19Z")

</div>

jake wrote:

> You are trying to find all the salable products in your store. You want  
> that code to go into the Product class. Then you will call
> 
> @products = Product.salable\_items to get the list of products in the  
> controller.

We say the same things with different words. What I meant was that in  
the OP’s code, salable\_items was defined in StoreController, when _HE_  
should have put it in Product instead.

–  
Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
JvYAML, RbYAML, JRuby and Jatha contributor  
System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))

“Yields falsehood when quined” yields falsehood when quined.

---

<div class="post-metadata">

**Author:** ![necrocyte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@necrocyte](https://www.ruby-forum.com/u/necrocyte)\
**Post date:** [August 6, 2006, 9:46pm UTC](https://www.ruby-forum.com/t/having-problem-w-agile-web-development-book/101620/5 "2006-08-06T21:46:55Z")

</div>

Ola B. wrote:

> jake wrote:
> 
> > You are trying to find all the salable products in your store. You want  
> > that code to go into the Product class. Then you will call
> > 
> > @products = Product.salable\_items to get the list of products in the  
> > controller.
> 
> We say the same things with different words. What I meant was that in  
> the OP’s code, salable\_items was defined in StoreController, when _HE_  
> should have put it in Product instead.
> 
> –  
> Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
> JvYAML, RbYAML, JRuby and Jatha contributor  
> System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
> OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))
> 
> “Yields falsehood when quined” yields falsehood when quined.

ahh,

i thought that was him. I should read a little more 🙂

sorry about that

–jake

---

<div class="post-metadata">

**Author:** ![necrocyte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@necrocyte](https://www.ruby-forum.com/u/necrocyte)\
**Post date:** [August 7, 2006, 3:20am UTC](https://www.ruby-forum.com/t/having-problem-w-agile-web-development-book/101620/6 "2006-08-07T03:20:45Z")

</div>

Jake V. wrote:

> Ola B. wrote:
> 
> > jake wrote:
> > 
> > > You are trying to find all the salable products in your store. You want  
> > > that code to go into the Product class. Then you will call
> > > 
> > > @products = Product.salable\_items to get the list of products in the  
> > > controller.

,

> i thought that was him. I should read a little more 🙂
> 
> sorry about that
> 
> –jake

Thanks that worked great ! 🙂

---

<div class="post-metadata">

**Author:** ![necrocyte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8797f3/32.png) [@necrocyte](https://www.ruby-forum.com/u/necrocyte)\
**Post date:** [August 6, 2006, 9:27pm UTC](https://www.ruby-forum.com/t/having-problem-w-agile-web-development-book/101620/7 "2006-08-06T21:27:16Z")

</div>

Ola B. wrote:

> Chad Saunders wrote:
> 
> > @products = Product.salable\_items
> 
> salable\_items are defined in the StoreController class, not in the  
> Product class.
> 
> –  
> Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
> JvYAML, RbYAML, JRuby and Jatha contributor  
> System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
> OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))
> 
> “Yields falsehood when quined” yields falsehood when quined.

actually, its not.

You are trying to find all the salable products in your store. You want  
that code to go into the Product class. Then you will call

@products = Product.salable\_items to get the list of products in the  
controller.

peace

–jake
