【发布时间】:2015-01-29 22:52:20
【问题描述】:
在 Rails 应用程序中,我正在尝试将图像(徽标)嵌入(内联)到电子邮件中。
这是 invoice.mailer.rb:
class InvoiceMailer < ActionMailer::Base
def invoice_email(invoice)
@invoice = invoice
@recipients = @invoice.workorder.client.contacts.where(:receiveinvoices => true)
tomail = @recipients.collect(&:email).join(",")
frommail = @invoice.tenant.from_email
copymail = @invoice.tenant.copy_email
attachments.inline['AME_Logo.gif'] = File.read( Rails.root.join('app/assets/images/AME_Logo.gif') )
mail(
:to => tomail,
:bcc => copymail,
:from => frommail,
:subject => "New Invoice from " + @invoice.tenant.name
)
end
end
这是 _invoice_email.html.erb:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" media="screen">
</style>
</head>
<body style="margin-left: auto; margin-right: auto; width: 700px">
<div class="invoice">
<div class="inv_header" style="margin-left:10px; margin-right: auto; width: 650px">
<h4>Invoice</h4>
<%= image_tag attachments['AME_Logo.gif'].url -%>
</div>
我从 image_tag 代码行收到此错误:
undefined local variable or method `attachments' for #<#<Class:0x007f8a49ce7b08>:0x007f8a4e352110>
感谢您的帮助!
【问题讨论】:
标签: ruby-on-rails