【发布时间】:2015-12-31 14:38:54
【问题描述】:
我们使用 WickedPdf,一个 wkhtmltopdf 包装器,用于在屏幕上生成大部分 PDF 文件,因为我们可以为 HTML 和 PDF 版本使用相同的 .haml 文件。
我想生成一些 PDF 文件以供将来使用。我们已经在邮件程序中执行了类似的操作来生成和附加 PDF。这工作正常...
# mailer
pdf = WickedPdf.new.pdf_from_string(render_to_string('account/customer_invoices/show_pdf.html', :layout => 'pdf'))
attachments["invoice.pdf"] = pdf
但是当我从模型而不是邮件程序中尝试相同的技巧时,我收到以下错误...
ActionView::Template::Error:
undefined method `root_url' for #<#<Class:0x007fad308a8538>:0x007fad308a83d0>
我看到的从模型中访问 root_url 的标准答案是添加以下内容,但它不起作用,因为我实际上是从视图而不是模型访问它。
include Rails.application.routes.url_helpers
【问题讨论】:
标签: ruby-on-rails pdf wkhtmltopdf wicked-pdf