代码
def download_report
@downloads = StatisticDownload.select("date(Date) as downloaded_date, count(id) as count").where("DownloadSuccess=?","1").group("date(Date)")
respond_to do |format|
format.pdf { @downloads }
end
end
创建视图
# download_report.pdf.prawn
pdf.text "Download ##{@downloads.id}", :size => 30, :style => :bold
downloads = @downloads.map do |downloads|
[
downloads.file,
downloads.id
]
end
但../generate_report.pdf会生成错误: 当你没有期待它时,你有一个零对象! 您可能期望一个Array实例。 评估nil.map时发生错误
我已经安装了0.12.0 prawn和prawnto。
答案 0 :(得分:2)
为此,请参阅http://www.idyllic-software.com/blog/creating-pdf-using-prawn-in-ruby-on-rails/
你可以找到简单的解决方案..
答案 1 :(得分:0)
尝试删除整个respond_to
块,以便您拥有:
def download_report
@downloads = StatisticDownload.select("date(Date) as downloaded_date, count(id) as count").where("DownloadSuccess=?","1").group("date(Date)")
end
或者,如果您确实需要respond_to块,请不要在format.pdf
后指定一个块:
def download_report
@downloads = StatisticDownload.select("date(Date) as downloaded_date, count(id) as count").where("DownloadSuccess=?","1").group("date(Date)")
respond_to do |format|
format.pdf
end
end
在这两种情况下,我猜你需要让prawnto的控制器魔法接管。