【问题标题】:Ruby on rails : detect the date of downloaded fileRuby on rails:检测下载文件的日期
【发布时间】:2018-09-06 14:38:38
【问题描述】:

我正在处理使用 ruby​​zip gem 使用 ruby​​ on rails 压缩和下载文件的任务,我想检查下载的最后日期。 这是完成工作的方法:

def zip_it
    report = Report.find( params[ :id ] ).decorate
    pdf_filename = report.decorate.attachment_pdf_filename
    binding.pry

    public_pdf    = ReportPdf.new current_company, report, []
    public_pdf.generate_pdf( report, "public.pdf" )

    internal_pdf    = ReportPdf.new current_company, report, [], "internal"
    internal_pdf.generate_pdf( report, "internal.pdf"  )

    zip_pdf( "#{Rails.root}/tmp/pdf/reports/#{report.reference}" )

    send_file( "#{Rails.root}/tmp/pdf/reports/#{report.reference}.zip"  )
    download_date = DateTime.current
    binding.pry
  end

当我检查 download_date 变量时,它返回 nil !

一些帮助!谢谢

【问题讨论】:

  • 这是一个变量,我想在上面保存文件的下载时间
  • 您是否包括:require 'date'?
  • 感谢@SaraTibbetts

标签: ruby-on-rails ruby datetime download


【解决方案1】:

为了使DateTime.current 按预期工作,您需要需要该库。

添加require 'date' 以解决您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    • 2018-01-03
    • 2011-06-24
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    相关资源
    最近更新 更多