Pergunta

In a ruby on rails application prawn ,prawnto is used to generate pdf raises some error..

 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 

Code in 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 gives a blank page as output

/admin/generate_report.pdf gives an error

  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

how can i rectify this error

Foi útil?

Solução

May be worth going to http://railscasts.com/episodes/153-pdfs-with-prawn-revised and following the tutorial, you will have to subscribe to watch if you haven't got a pro subscription though.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top