【发布时间】:2018-12-28 03:24:49
【问题描述】:
我正在开发一个具有将index 视图导出为 PDF 的功能的项目。这一切都与Wicked PDF gem 完美配合,但是,在生产中,生成的 PDF 会被浏览器缓存,因此可能会过期。刷新 PDF 视图确实会获取最新数据,但简单地导航到 PDF 视图似乎只使用浏览器缓存的文档。有没有办法防止 PDF 视图被浏览器缓存?
控制器
class InvoicesController < ApplicationController
# GET /invoices
def index
@invoices = Invoice.all
respond_to do |format|
format.html
format.pdf do
render pdf: "Invoices_#{Time.current.strftime("%Y_%m_%d_at_%H_%M")}",
template: 'invoices/index',
show_as_html: params.key?('debug'),
title: "Invoices_#{Time.current.strftime("%Y_%m_%d_at_%H_%M")}", # otherwise first page title is used
orientation: :landscape,
margin: { top: 15, # default 10 (mm)
bottom: 15,
left: 15,
right: 45 },
footer: { left: "Extracted: #{Time.current.to_formatted_s(:date_at_time)}",
right: "Page [page] of [topage]" }
end
end
end
end
任何建议将不胜感激。
【问题讨论】:
标签: ruby-on-rails pdf browser-cache wicked-pdf