Rails发送过时的文件

时间:2012-08-04 21:03:52

标签: ruby-on-rails ruby ruby-on-rails-3

所以我有一个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' %>继续向我发送过去生成的文件,包括旧文件名。如何删除这些oldfiles并强制Rails生成一个新文件?

0 个答案:

没有答案