簡體   English   中英

Ruby on Rails-大蝦和大蝦錯誤

[英]Ruby on rails -prawn & prawnto error

在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

我該如何糾正此錯誤

也許值得去http://railscasts.com/episodes/153-pdfs-with-prawn-revised,並按照該教程進行操作,但是如果您尚未獲得專業訂閱,則必須訂閱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM