0

在 ruby​​ on rails 应用程序 prawn 中,prawnto 用于生成 pdf 会引发一些错误..

 def generate_report

    generate_report = params[:report_type]

# puts(generate_report)

if generate_report == "1"
       # get count of all successful downloads
  @total_downloads=StatisticDownload.where("DownloadSuccess=?","1").count
  #puts(@total_downloads)
  # get all downloads grouped by date
  @downloads  = StatisticDownload.select("date(Date) as downloaded_date, count(id) as count").where("DownloadSuccess=?","1").group("date(Date)")
  respond_to do |format|
    format.pdf { render :layout => false }
   end  
         end 

generate_report.pdf.prawn 中的代码

        pdf.move_down(30) 
      book =  @downloads.map do |item|
     [
       item.downloaded_date,
         item.count
     ]
      end
         pdf.table book, :border_style => :grid,
        :row_colors => ["FFFFFF", "DDDDDD"],
        :headers => ["downloaded_date", "count"],
        :align => { 0 => :left, 1 => :right, 2 => :right, 3 => :right }

/admin/generate_report 给出一个空白页作为输出

/admin/generate_report.pdf 给出错误

  You have a nil object when you didn't expect it!
  You might have expected an instance of Array.
  The error occurred while evaluating nil.map
  Extracted source (around line #2):

     1: pdf.move_down(30) 
      2: book =  @downloads.map do |item|
      3:  [
    4:   item.downloaded_date,
     5:   item.count

我该如何纠正这个错误

4

1 回答 1

-1

可能值得去http://railscasts.com/episodes/153-pdfs-with-prawn-revised并按照教程进行操作,如果您还没有获得专业订阅,则必须订阅观看。

于 2011-12-15T11:20:05.923 回答