我在静态页面上有这个远程表单。
<%= form_tag(reports_products_path, :method => "post", :action => "products", :remote => true) do%>
<%= submit_tag "Generate Product Report" %>
<% end %>
这是我提交该表单时触发的控制器操作:
def products
@products = Product.joins(:client).all
respond_to do |format|
format.html
format.pdf
format.js do
pdf = PrintedProductPdf.new(@products)
File.open("public/product_report/product#{Date.today}.pdf", "wb") { |f| f << pdf.render }
send_data pdf.render,
file_name: "public/product_report/product#{Date.today}.pdf",
:type => "application/pdf",
:disposition => "attachment"
end
end
端
单击表单链接时文件将写入。但是,我希望能够在单击表单中的提交按钮时下载文件。发送数据功能似乎是将附件发送到lala land