undefined method `symbolize_keys!' for #<Array rails 4

573 Views Asked by At

In 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
              ])

I am using mandrill_mail in my rails application.I want to send mail with multiple attachments. But getting error in the each loop undefined methodsymbolize_keys!' for #

1

There are 1 best solutions below

0
On BEST ANSWER

Try

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

Use map to return an array of each block return value.

You get this error because it tries to symbolize_keys! on the first value of :attachments array, which is also an array (Array#each returns the object itself when a block is provided).