Forum: Ruby on Rails Accessing overridden method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jeffrey L. Taylor (Guest)
on 2006-03-18 17:22
(Received via mailing list)
I have two model classes:

class Item < ActiveRecord::Base
  belongs_to :channel, :counter_cache => true
  validates_presence_of :channel
end


class Channel < ActiveRecord::Base
  has_many :items, :dependent => true
end


In the Channel controller I have variable channel.items, an Array of
Items.  I would like to use the Array find method.  However,
channel.items.find() is a Rails database query method.  Is there any
way I can access the built-in Array find() method?

TIA,
  Jeffrey
Ray B. (Guest)
on 2006-03-18 19:57
(Received via mailing list)
Jeffrey L. Taylor wrote:
> end
>
>
> In the Channel controller I have variable channel.items, an Array of
> Items.  I would like to use the Array find method.  However,
> channel.items.find() is a Rails database query method.  Is there any
> way I can access the built-in Array find() method?

Array.find is a synonym for detect.

Ray
Ezra Z. (Guest)
on 2006-03-19 03:20
(Received via mailing list)
On Mar 18, 2006, at 9:56 AM, Ray B. wrote:

>> Items.  I would like to use the Array find method.  However,
>> channel.items.find() is a Rails database query method.  Is there any
>> way I can access the built-in Array find() method?
>
> Array.find is a synonym for detect.
>
> Ray
>

Yep and you can always use a to_a to make sure you are using array find:


>> channel.items.to_a.find

-Ezra
Jeffrey L. Taylor (Guest)
on 2006-03-19 13:17
(Received via mailing list)
Quoting Ray B. <removed_email_address@domain.invalid>:
> >  has_many :items, :dependent => true
> >end
> >
> >
> >In the Channel controller I have variable channel.items, an Array of
> >Items.  I would like to use the Array find method.  However,
> >channel.items.find() is a Rails database query method.  Is there any
> >way I can access the built-in Array find() method?
>
> Array.find is a synonym for detect.
>

Thanks, Ray.  This works.

Jeffrey
Jeffrey L. Taylor (Guest)
on 2006-03-19 13:17
(Received via mailing list)
Quoting Ezra Z. <removed_email_address@domain.invalid>:
> >>  has_many :items, :dependent => true
>
> Yep and you can always use a to_a to make sure you are using array find:
>
>
> >>channel.items.to_a.find
>

Ezra, thanks.  This also works.

Jeffrey
This topic is locked and can not be replied to.