代码之家  ›  专栏  ›  技术社区  ›  millisami

在Rails中存储上一年的旧数据?

  •  0
  • millisami  · 技术社区  · 16 年前

    我正在开发一个有大量数据输入的应用程序。 这是一个类似的活动,它有诸如每平方英尺的价格、开始日期、结束日期等属性。i、 e最长日期约为30天。

    现在我很困惑,如何将这些活动存储为报告,以便不定期访问。我的意思是以这样一种方式存储,它将像未来几年的报告一样工作?

    它有点像会计年度,在会计年度中,上一年度的报告与所有计算一起存储,以便在以后检索时,不应执行所有算法和计算。类似于冻结数据的东西??

    1 回复  |  直到 16 年前
        1
  •  0
  •   Harish Shetty    16 年前

    您可以将活动报告存储在数据库或文件系统中。可在第一次请求存档活动时生成报告。

    class Campaign < ActiveRecord::Base   
      # Campaign model has an attribute called report_file
      def report_file
        return nil unless expired?
        attributes['report_file'] ||= generate_report_file
      end
    
      def generate_report_file
        return nil if attributes['report_file']
        # Generate the report using Prawn PDF OR wickedPDF etc.
        # Update report_file attribute with the report file location
        # Return the file location
      end
    end
    
    class CampaignsController < ApplicationController
      before_filter :check_expiry, :only => :show
      def report
        if @campaign.report_file
          send_file(@campaign.report_file)
        else
          # handle error
        end
      end
      def show
      end
      def check_expiry
        @campaign = Campaign.find(params[:id])
        if @campaign.expired?
          render :report
        end
      end
    end