我正在使用wicked-pdf来简化在我的Rails 5应用程序中生成pdf发票。我有两个动作使用wicked-pdf的pdf功能。第一个动作生成PDF并在一个新的浏览器窗口中呈现它。第二种方法将pdf附加到电子邮件中。使用wicked_pdf和rails编码错误ActiveJob
这两个操作都很好。当我使用ActiveJob/Sidekiq将我的PDF邮件程序设置为'deliver_later'时,问题就出现了。当我添加 'deliver_later' 我提出了一个错误,指出:
从ASCII-8BIT “\ xFE如果” 为UTF-8
,如果我使用了 “deliver_now” 这个错误不会发生命令。使用“deliver_now”发送电子邮件并正确附加PDF。
下面是一些我为邮件行动,邮件和工作代码:
invoices_controller.rb
...
def create
respond_to do |format|
format.html do
pdf = render_to_string(pdf: @order.ruling_invoice,
template: "orders/invoices/show.pdf.haml",
encoding: "utf8",
locals: { order: @order.decorate}
)
SendInvoiceMailJob.new.perform(@order, pdf, @order.token)
redirect_to order_url(id: @order.id, subdomain: current_company.slug), notice: "This invoice has been emailed."
end
end
end
...
send_invoice_mail_job.rb
...
def perform(order, pdf, order_token)
InvoiceMailer.send_invoice(order, pdf, order_token).deliver_later
end
...
invoice_mailer。 rb
...
def send_invoice(order, pdf_invoice , invoice_token)
@order = order
attachments["#{invoice_token}.pdf"] = pdf_invoice
mail(
to: @order.email,
from: @order.seller_email
)
end
...
为什么此代码使用send_invoice_mail_job.rb中的“deliver_now”工作,但它无法使用“deliver_later”?
您是否找到解决方案?我有同样的问题 – moondaisy
@moondaisy我做过。我不得不去看看我做了什么,虽然我不记得清楚 – Herm
如果你碰巧有时间,请将它作为答案发布在这里:)我还没有发现任何其他问题提到这个或如何做到这一点的例子 – moondaisy