Wicked_pdf 多个 pdf 同一个页面

Wicked_pdf multiple pdf's one same page

是否可以使用 wicked_pdf 在一个页面上有多个 pdf 链接?我似乎找不到这方面的任何信息。

例如,我有一份每日销售报告和一份每周销售报告,我希望可以在展示页面上以 pdf 格式下载它们。

控制器

format.pdf do
 render pdf: "#{@sales.name}", 
 template: 'trials/sales_day_report',
 disposition: 'attachment'
end
format.pdf do
 render pdf: "#{@sales.name}", 
 template: 'trials/sales_weekly_report',
 disposition: 'attachment'
end

显示

<%= link_to 'Download Daily Report', sale_path(format: 'pdf') %>
<%= link_to 'Download Weekly Report', sale_path(format: 'pdf') %>

你需要像这样在你的链接中传递一个额外的参数:

<%= link_to 'Download Daily Report', sale_path(format: 'pdf', sale_type: 'daily') %>
<%= link_to 'Download Weekly Report', sale_path(format: 'pdf', sale_type: 'weekly') %>

然后,在您的 pdf 模板路径中插入该参数:

format.pdf do
  render pdf: "#{@sales.name}",
  template: "trials/sales_#{params[:sale_type]}_report",
  disposition: 'attachment'
end