【问题标题】:Can't access root_url method when building a PDF file offline using WickedPdf使用 WickedPdf 离线构建 PDF 文件时无法访问 root_url 方法
【发布时间】: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


    【解决方案1】:

    如果我理解正确,您在视图中调用root_url

    尝试将其更改为

    Rails.application.routes.url_helpers.root_url
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多