我正在使用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