在一个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我如何纠正这个错误?
发布于 2011-12-15 19:20:06
可能值得访问http://railscasts.com/episodes/153-pdfs-with-prawn-revised并按照教程进行操作,但如果您没有获得专业订阅,则必须订阅观看。
https://stackoverflow.com/questions/8518260
复制相似问题