[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Finding an object in a collection

Pieter Mans

12/18/2006 2:50:00 AM

How would I go about finding an object in a collection? Specifically:

I have a collection called roles. I have a Role object with the name
property "user". How do I find that object in roles?

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

2 Answers

Tim Hunter

12/18/2006 3:03:00 AM

0

Pieter Mans wrote:
> How would I go about finding an object in a collection? Specifically:
>
> I have a collection called roles. I have a Role object with the name
> property "user". How do I find that object in roles?
>
>
ri Enumerable.find


Pieter Mans

12/18/2006 4:16:00 AM

0

Daniel ----- wrote:
> On 12/18/06, Pieter Mans <tybriel@gmail.com> wrote:
>>
>> How would I go about finding an object in a collection? Specifically:
>>
>> I have a collection called roles. I have a Role object with the name
>> property "user". How do I find that object in roles?
>>
>> --
>> Posted via http://www.ruby-....
>>
>> I believe you can use dynamic finders on AR collections.
>
> @roles_collection.find_by_name( "user" )

This worked great, thanks!

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