В prawn приложения ruby on rails 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
как я могу исправить эту ошибку