# Collect

**URL:** <https://www.ruby-forum.com/t/collect/148104>\
**Category:** Ruby\
**Created:** [September 9, 2008, 11:20am UTC](https://www.ruby-forum.com/t/collect/148104 "2008-09-09T11:20:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [September 9, 2008, 11:20am UTC](https://www.ruby-forum.com/t/collect/148104/1 "2008-09-09T11:20:32Z")

</div>

Hi  
I have to collect mail addresses like below

Contact.find\_by\_id(problem.reported\_by\_id).contact\_email\_addresses.find(:all,  
:conditions =\> [‘contact\_email\_address\_type\_id=?’,2])

Executing above what i am getting is two objects of class  
ContactEmailAddress and in that an email field is there. For example  
removed\_email\_address@domain.invalid and removed\_email\_address@domain.invalid  
So how can I collect this to an array ? I tried like

EmailArray \<\<  
Contact.find\_by\_id(problem.reported\_by\_id).contact\_email\_addresses.find(:all,  
:conditions =\> [‘contact\_email\_address\_type\_id=?’,2]).collect { |mail|  
mail.email}

```
  But is not working.Could you please tell me how I can achieve

```

this?The above is clearly problem.reported\_by\_id (ie MailIds of  
ReportedBy person) My code continues like

Contact.find\_by\_id(problem.analyst\_id).contact\_email\_addresses.find(:all,  
:conditions =\> [‘contact\_email\_address\_type\_id=?’,2])  
Please note analyst\_id above…I have to do the same thing to this  
also ie to collect mails of Analyst also like above to the same  
EmailArray…Like that

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [September 9, 2008, 12:26pm UTC](https://www.ruby-forum.com/t/collect/148104/2 "2008-09-09T12:26:28Z")

</div>

Hi  
Here I tried like  
email\_array = Contact.get\_email\_ids\_of\_contacts(problem.reported\_by\_id)  
unless problem.reported\_by\_id.empty?  
It worked and I got the two mailIDs But when I add the next line  
like  
email\_array = email\_array +  
Contact.get\_email\_ids\_of\_contacts(problem.analyst\_id) unless  
problem.analyst\_id.empty?

```
 Now it is not working What might be the cause.Please help

```

Note:  
In get\_email\_ids\_of\_contacts of Contact model just wrote  
return  
Contact.find\_by\_id(contact\_id).contact\_email\_addresses.find(:all,  
:conditions =\> [‘contact\_email\_address\_type\_id=?’,2]).collect { |mail|  
mail.email}

Sijo
