Skip to content

Instantly share code, notes, and snippets.

@danielwestendorf
Created November 6, 2018 20:53
Show Gist options
  • Save danielwestendorf/1af596b6ac06044d6f7b33b78d139536 to your computer and use it in GitHub Desktop.
Save danielwestendorf/1af596b6ac06044d6f7b33b78d139536 to your computer and use it in GitHub Desktop.
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