Module: QueryReport::Helper
- Defined in:
- lib/query_report/helper.rb
Instance Method Summary collapse
- #generate_csv_for_report(records) ⇒ Object
- #query_report_pdf_template_class ⇒ Object
- #render_report ⇒ Object
- #reporter(query, options = {}, &block) ⇒ Object
Instance Method Details
#generate_csv_for_report(records) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/query_report/helper.rb', line 38 def generate_csv_for_report(records) if records.size > 0 columns = records.first.keys CSV.generate do |csv| csv << columns records.each do |record| csv << record.values.collect { |val| val.kind_of?(String) ? view_context.strip_links(val) : val } end end else nil end end |
#query_report_pdf_template_class ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/query_report/helper.rb', line 29 def query_report_pdf_template_class = QueryReport.config. if [:template_class] @template_class ||= [:template_class].to_s.constantize return @template_class end return QueryReport::ReportPdf end |
#render_report ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/query_report/helper.rb', line 19 def render_report respond_to do |format| format.js { render 'query_report/list' } format.html { render 'query_report/list' } format.json { render json: @report.all_records } format.csv { send_data generate_csv_for_report(@report.all_records), :disposition => "attachment;" } format.pdf { send_data query_report_pdf_template_class.new(@report).to_pdf.render } end end |
#reporter(query, options = {}, &block) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/query_report/helper.rb', line 12 def reporter(query, ={}, &block) @report ||= QueryReport::Report.new(params, view_context, ) @report.query = query @report.instance_eval &block render_report end |