Created
November 6, 2018 20:53
-
-
Save danielwestendorf/1af596b6ac06044d6f7b33b78d139536 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Report | |
def pdf_url | |
Rails.cache.fetch(["v1/report-pdf-url", self]) do | |
asset_host = Rails.env.production? ? Rails.application.config.action_controller.asset_host : "http://localhost:3000" | |
metadata = { width: 8.5, width: 11 } | |
renderer = ReportsController.renderer.new(https: true) | |
html = renderer.render(template: "reports/show", assigns: { report: self }) | |
pdf = BreezyPDF::HTML2PDF.new(asset_host, html, metadata) | |
pdf.to_url | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment