Problem with array

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 you can try like this

@report_admins = ReportAdmin.find(:all)

@recipients=[]

for report_admin in @report_admins
@recipients << report_admin.email
end

Brilliant thanks!

Andrew

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 }

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.

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

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 ?

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.