将电子邮件发送给多个收件人actionmailer

时间:2012-03-02 12:14:56

标签: ruby-on-rails ruby actionmailer

我有 invitation_mailer.rb 下一个:

class InvitationMailer < ActionMailer::Base
  default :from => "email@email.com"
  def invitation_friends(invitation, user)
   @user = user
   @invitation = invitation
   mail(:bcc => @invitation.recipients.map(&:recipients), :subject => "Subject email")
  end
end

@ invitation.recipients 是一个包含以下电子邮件的数组:

 ["email1@example.com","email2@example.com"]

但我接下来记录下来了:

NoMethodError (undefined method `recipients' for "email1@example.com":String):

我做错了什么?

谢谢!

2 个答案:

答案 0 :(得分:5)

尝试@invitations.recipients.join("; ")

您正在尝试调用:数组中String对象上的收件人,这无法正常工作。

答案 1 :(得分:1)

我相信这一行:

@invitation.recipients.map(&:recipients)

实际应该是:

@invitation.recipients.join(';')

map(&:recipients)表示:对数组中的每个元素调用#recipients方法。你得到他的错误,因为你的数组包含字符串,显然String没有方法#recipients:)