所以我有一个 Rails 应用程序,它在我的输出一些文件folhas_controller.rb
:
def show
@folha = Folha.find(params[:id])
@servicos = @folha.servicos
nome = "#{@folha.nome_do_mes}-#{@folha.ano}-#{DateTime.now.to_i}"
respond_to do |format|
format.csv { send_data @folha.to_csv, filename: "#{nome}.csv" }
format.xlsx do
xlsx_package = @folha.to_xls
begin
temp = Tempfile.new("folha.xlsx")
xlsx_package.serialize temp.path
xlsx_package.use_shared_strings
send_file temp.path, filename: "#{nome}.xlsx", type: "application/xlsx"
ensure
temp.close
temp.unlink
end
end
format.pdf do
pdf = @folha.to_pdf(view_context)
send_data pdf.render, filename: "#{nome}.pdf", type: "application/pdf"#, disposition: "inline"
end
end
end
事情在发展中很好。然后我部署到heroku,并<%= link_to image_tag('xls_small.png'), folha_path(folha, format: 'xlsx'), class: 'item' %>
不断向我发送过去生成的文件,包括旧文件名。如何删除这些旧文件并强制 Rails 生成一个新文件?