我在静态页面上有这个远程表单。
<%= 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
结尾
单击表单链接时文件会写入。但是,我希望能够在单击表单中的提交按钮时下载文件。发送数据功能好像是把附件发送到啦啦乐园