Accessing overridden method


#1

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


#2

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


#3

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


#4

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


#5

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