cyu
5/25/2009 - 1:07 AM

report_controller.rb

class ReportController < ApplicationController
  after_filter :cache_weekly_report, :only => :show
  
  def show
    if params[:year]
      @year  = params[:year]
      @month = params[:month]
      @day   = params[:day]
      if File.exist?("#{Rails.root}/public/report/#{@year}/#{@month}/#{@day}.html")
        redirect_to reports_path(:year => @year, :month => @month, :day => @day)
      else
        # render report for a specific day
      end
    else
      today  = Date.today
      @year  = today.year
      @month = today.month
      @day   = today.day
      
      # render report for the current week
    end
  end
  
  protected
  
    def cache_weekly_report
      cache_page(response.body, "/report/#{@year}/#{@month}/#{@day}.html") if @year
    end
    
end