Undefined method `mime_type` in Mailer view when using attachments
I created a mailer in my Rails 4 application that works great when there are no email attachments. However, when I add the PDF attachment for emails, I get the following error when I try to preview the email ... / rails / mailers / donor _mailer / thankyou_mail_preview
NoMethodError in Rails::Mailers#preview
Showing /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.1.6/lib/rails/templates/rails/mailers/email.html.erb where line #95 raised:
<iframe seamless name="messageBody" src="?part=<%= Rack::Utils.escape(@part.mime_type) %>"></iframe>
However, I don't get this error or any problems at all when sending the emails themselves, only with the preview. Has anyone else experienced this and knows how to fix it / knows the direction I should be going. Could this lead to further problems with my email, or is it just a problem with the preview function?
My Mailer looks like this:
class DonorMailer < ActionMailer::Base
default from: "user@gmail.com"
def thankyou_email(computer)
@computer = computer
@donor = computer.donor
attachments["some.pdf"] = File.read("path/to/pdf/some.pdf")
mail(to: @donor.donor_email, subject: "Thank you")
end
end
and the template:
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<p>Email content here</p>
</body>
</html>
I tried adding: pdf to my MIME types to no avail.
thank
+3
source to share
No one has answered this question yet
Check out similar questions: