Re: Method on a array of objects from the database

Pierre Valade
Fri, 30 Nov 2007 09:20:16 -0000

Thanks you ! It''s great !
Pierre

On 29 nov, 22:37, Ilan Berci
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
> > @products = Product.find(:all)
>
> > 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 viahttp://www.ruby-forum.com/.