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
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
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
Quoting Ray B. [email protected]:
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
Quoting Ezra Z. [email protected]:
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