我正在使用rails4,在我的 Controller 页面中我有如下所示的xl下载。
一切正常,但当我使用浏览器的后退和前进按钮时,它会一次又一次下载相同的内容。怎么能 ?摆脱它吗?
def download_report
@acquisitions = AcquisitionReport.generate(params[:acquisition_id].to_i, params[:portfolio_id])
cookies[:fileDownload] = 'true'
render xlsx: 'download_report',filename: "report.xlsx"
end
最佳答案
我认为,你必须保持 session
def download_report
@acquisitions = AcquisitionReport.generate(params[:acquisition_id].to_i, params[:portfolio_id])
if session[:test] == true
session[:test] = nil
render xlsx: 'download_report',filename: "report.xlsx"
else
render :nothing => true, :status => 200, :content_type => 'text/html'
end
end
关于javascript - 防止通过浏览器后退和前进按钮下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30451604/