undefined方法`symbolize_keys!'对于#<array rails =“”4 =“”

时间:2015-06-09 06:20:32

标签: ruby-on-rails ruby-on-rails-4 mandrill

=“”

mcs_mailer.rb

 def invite(email,subject,body,attachment_urls)

 @attachment_urls= attachment_urls

 mandrill_mail(
  template: 'group-invite',
  subject: subject,
  to: email,
  html: body,
  attachments: [ @attachment_urls.each do |url|
                {
                  content: File.read(url),
                  name: 'offer.pdf',
                  type: 'application/pdf'
                }
              end
              ])

我在我的rails应用程序中使用mandrill_mail。我想发送带有多个附件的邮件。但是在每个循环undefined method symbolize_keys中得到错误!'为#

1 个答案:

答案 0 :(得分:1)

尝试

# [...]
attachments: @attachment_urls.map do |url|
  {
     # [...]
  }
end

使用map返回每个块返回值的数组。

您收到此错误是因为它在symbolize_keys!数组的第一个值上尝试:attachments,该数组也是一个数组(Array#each在提供块时返回对象本身)。