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?
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: [email protected]
web: http://stoneship.org/
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)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (http://www.ologix.com)
“Yields falsehood when quined” yields falsehood when quined.
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)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (http://www.ologix.com)
“Yields falsehood when quined” yields falsehood when quined.
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)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (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
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 ! 
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)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (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