您可以将活动报告存储在数据库或文件系统中。可在第一次请求存档活动时生成报告。
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