Action mailer, error Subject: Header must not be multiple

i want to send multiple emails:

   #my Controller

def send_email
  if params[:group_ids]
  groups = Group.find(params[:group_ids]) # creates an array called 

‘groups’ that looks like : [{:id => 1, :title => ‘yediot’}, {:id => 2,
:title => ‘maariv’} ] — [ 1, 2 ]
else
groups = []
end
names = []
emails = []
grouptitle = []
pages = []
groups.each { |group| # do a loop for {:id=> 1 …} and then do
another loop {:id => 2 … } until the end of the array, and then
continue to the next line # group.users - - > [{:id => 3, :email =>
[email protected]’, :name => ‘aaa’ }, {:id => 454, :email => ‘[email protected]’,
:name => ‘lsls’ }]
group.users.each {|a|
emails << a.email
names << a.name
}
groups.each { |group |
grouptitle << group.title
}
groups.each { |group|
group.pages.each {|page|
pages << page.body
}}
}

    Mailer.deliver_contact_us(
       :recipients =>  emails,
	:subject => grouptitle, #the error comes from this line
	:body => { :name => names,
                   :phone => '08-9492332',
                   :email => emails,
                   :message => pages,
		},

       :from => "[email protected]"
    )
end



    #my email Model(mailer.rb)

class Mailer < ActionMailer::Base

helper ActionView::Helpers::UrlHelper

def generic_mailer(options)
@recipients = options[:recipients]
@from = options[:from]
@cc = options[:cc] || “”
@bcc = options[:bcc] || “”
@subject = options[:subject] || “this is my great message”
@body = options[:body] || {}
@headers = options[:headers] || {}
@charset = options[:charset] || “utf-8”
end

Create placeholders for whichever e-mails you need to deal with.

Override mail elements where necessary

def contact_us(options)
self.generic_mailer(options)
end

end

rails error message: “Subject: Header must not be multiple”

**has anyone encounter this error???

thanks

You’re trying to set the subject of the email to an array, which clearly
is not a reasonable thing to expect.

Fred

Frederick C. wrote:

You’re trying to set the subject of the email to an array, which clearly
is not a reasonable thing to expect.

Fred

can you guide me?

I’ve no idea what you want to set as the subject line of your email, but
just don’t set it to be an array, i.e. set grouptitle to a string. If
you want different subject lines for each emails I believe you’ll need
to create emails one by one.

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs