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? -- Posted via http://www.ruby-forum.com/.
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 > endDefine self.salable_items in your Product class, not your StoreController class. Regards, Denis Defreyne -- mail: denis.defreyne@stoneship.org web: http://stoneship.org/
Chad Saunders wrote:> 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? >salable_items are defined in the StoreController class, not in the Product class. -- Ola Bini (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 Bini wrote:> Chad Saunders wrote: >> @products = Product.salable_items >> > salable_items are defined in the StoreController class, not in the > Product class. > > > > -- > Ola Bini (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 -- Posted via http://www.ruby-forum.com/.
jake wrote:> Ola Bini wrote: >> Chad Saunders wrote: >>> @products = Product.salable_items >>> >> salable_items are defined in the StoreController class, not in the >> Product class. >> > > 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.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 Bini (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 Varghese
2006-Aug-06 19:47 UTC
[Rails] Re: Re: Having Problem w/ Agile Web Development book
Ola Bini 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 Bini (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 -- Posted via http://www.ruby-forum.com/.
Chad Saunders
2006-Aug-07 01:20 UTC
[Rails] Re: Re: Having Problem w/ Agile Web Development book
Jake Varghese wrote:> Ola Bini 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 > > --jakeThanks that worked great ! :) -- Posted via http://www.ruby-forum.com/.