Sha256: bb9b38f659b50390a18d65c5899f80dbd0615ae94b6f0a9193b1f34c6b512cc7

Contents?: true

Size: 940 Bytes

Versions: 3

Compression:

Stored size: 940 Bytes

Contents

module Dossier
  class ReportsController < ApplicationController
    def show
      report = report_class.new(params[:options] || {})
      report.run

      respond_to do |format|
        format.html do
          begin
            render template: "dossier/reports/#{report.view}", locals: {report: report}
          rescue ActionView::MissingTemplate => e
            render template: 'dossier/reports/show', locals: {report: report}
          end
        end

        format.json do
          render :json => report.results.hashes
        end

        format.csv do
          headers["Content-Disposition"] = %[attachment;filename=#{params[:report]}-report_#{Time.now.strftime('%m-%d-%Y-%H%M%S')}.csv]
          self.response_body = StreamCSV.new(report.raw_results.arrays)
        end
      end
    end

    private

    def report_class
      "#{params[:report].split('_').map(&:capitalize).join}Report".constantize
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dossier-2.1.1 app/controllers/dossier/reports_controller.rb
dossier-2.1.0 app/controllers/dossier/reports_controller.rb
dossier-2.0.1 app/controllers/dossier/reports_controller.rb