# Problem with array

**URL:** <https://www.ruby-forum.com/t/problem-with-array/144496>\
**Category:** Rails\
**Created:** [July 30, 2008, 10:19am UTC](https://www.ruby-forum.com/t/problem-with-array/144496 "2008-07-30T10:19:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewdon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@andrewdon](https://www.ruby-forum.com/u/andrewdon)\
**Post date:** [July 30, 2008, 10:19am UTC](https://www.ruby-forum.com/t/problem-with-array/144496/1 "2008-07-30T10:19:47Z")

</div>

I have a list of 3 “report\_admins” in my database, and when I send an  
email I need to email to go to all 3 admins,

So in the controller I put…  
@report\_admins = ReportAdmin.find(:all)

Then I told ActionMailer this…  
@recipients = report\_admins.email

But when I try and send this email I get this error…  
undefined method `email’ for #Array:0x455e214

I have been told that I need to change this array into a string, but I  
don’t know how… How?

Andrew

---

<div class="post-metadata">

**Author:** ![andrewdon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@andrewdon](https://www.ruby-forum.com/u/andrewdon)\
**Post date:** [July 30, 2008, 10:37am UTC](https://www.ruby-forum.com/t/problem-with-array/144496/2 "2008-07-30T10:37:29Z")

</div>

Hi you can try like this

@report\_admins = ReportAdmin.find(:all)

@recipients=[]

for report\_admin in @report\_admins  
@recipients \<\< report\_admin.email  
end

---

<div class="post-metadata">

**Author:** ![andrewdon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@andrewdon](https://www.ruby-forum.com/u/andrewdon)\
**Post date:** [July 30, 2008, 10:43am UTC](https://www.ruby-forum.com/t/problem-with-array/144496/3 "2008-07-30T10:43:05Z")

</div>

Brilliant thanks!

Andrew

---

<div class="post-metadata">

**Author:** ![andrewdon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@andrewdon](https://www.ruby-forum.com/u/andrewdon)\
**Post date:** [July 30, 2008, 3:31pm UTC](https://www.ruby-forum.com/t/problem-with-array/144496/4 "2008-07-30T15:31:05Z")

</div>

babu nair wrote:

> Hi you can try like this
> 
> @report\_admins = ReportAdmin.find(:all)
> 
> @recipients=[]
> 
> for report\_admin in @report\_admins  
> @recipients \<\< report\_admin.email  
> end

You can collect the email address of each admin in one line:

@recipients = @report\_admins.collect { |a| a.email }

---

<div class="post-metadata">

**Author:** ![andrewdon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@andrewdon](https://www.ruby-forum.com/u/andrewdon)\
**Post date:** [July 30, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/problem-with-array/144496/5 "2008-07-30T19:45:29Z")

</div>

Jeremy Weiskotten wrote:

> babu nair wrote:
> 
> > Hi you can try like this
> > 
> > @report\_admins = ReportAdmin.find(:all)
> > 
> > @recipients=[]
> > 
> > for report\_admin in @report\_admins  
> > @recipients \<\< report\_admin.email  
> > end
> 
> You can collect the email address of each admin in one line:
> 
> @recipients = @report\_admins.collect { |a| a.email }

This way does seem like a much more efficient way of getting and doing  
this, but both ways work.

---

<div class="post-metadata">

**Author:** ![andrewdon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@andrewdon](https://www.ruby-forum.com/u/andrewdon)\
**Post date:** [July 30, 2008, 8:10pm UTC](https://www.ruby-forum.com/t/problem-with-array/144496/6 "2008-07-30T20:10:11Z")

</div>

Andrew D. wrote:

> I have a list of 3 “report\_admins” in my database, and when I send an  
> email I need to email to go to all 3 admins,
> 
> So in the controller I put…  
> @report\_admins = ReportAdmin.find(:all)
> 
> Then I told ActionMailer this…  
> @recipients = report\_admins.email
> 
> But when I try and send this email I get this error…  
> undefined method `email’ for #Array:0x455e214
> 
> I have been told that I need to change this array into a string, but I  
> don’t know how… How?
> 
> Andrew

Hi

when you write ReportAdmin.find(:all) it gives array as result. so u  
access each record through

---

<div class="post-metadata">

**Author:** ![andrewdon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@andrewdon](https://www.ruby-forum.com/u/andrewdon)\
**Post date:** [July 30, 2008, 8:58pm UTC](https://www.ruby-forum.com/t/problem-with-array/144496/7 "2008-07-30T20:58:09Z")

</div>

Andrew D. wrote:

> I have a list of 3 “report\_admins” in my database, and when I send an  
> email I need to email to go to all 3 admins,
> 
> So in the controller I put…  
> @report\_admins = ReportAdmin.find(:all)
> 
> Then I told ActionMailer this…  
> @recipients = report\_admins.email
> 
> But when I try and send this email I get this error…  
> undefined method `email’ for #Array:0x455e214
> 
> I have been told that I need to change this array into a string, but I  
> don’t know how… How?
> 
> Andrew

Hey I am facing same problem

what to do ?

---

<div class="post-metadata">

**Author:** ![andrewdon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@andrewdon](https://www.ruby-forum.com/u/andrewdon)\
**Post date:** [July 30, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/problem-with-array/144496/8 "2008-07-30T21:08:01Z")

</div>

Priyanka P. wrote:

> Hi
> 
> when you write @reportadmins = ReportAdmin.find(:all) it gives array as result. so you access each record through

```
     @emails = []

     for reportadmin in @reportadmins

          @emails - reportadmin.email

     end

```

Thanks,  
Priyanka P.  
Software Engineer  
Gloscon Solution Pvt. Ltd.
