Re: Method on a array of objects from the database

Ilan Berci
Thu, 29 Nov 2007 21:37:19 -0000

> And now I want to define a method which I could like
>
> @products.select_fruits
>
> having said somewhere :
>


module Foo
  def select_fruits
    # some code here
  end
end

# meanwhile.. back on the farm..
@products = Product.find(:all)
@products.extend Foo

=================== Or even better.. ========================class Product
  belongs_to :fruit, :extends => Foo
end

Look for "Association extensions" within the Rails api..

hth..

ilan

--
Posted via http://www.ruby-forum.com/.