Reputation: 718
code in controller
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
Created view
# download_report.pdf.prawn
pdf.text "Download ##{@downloads.id}", :size => 30, :style => :bold
downloads = @downloads.map do |downloads|
[
downloads.file,
downloads.id
]
end
But ../generate_report.pdf generates 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
i have installed prawn 0.12.0 and prawnto.
Upvotes: 1
Views: 1229
Reputation: 89
For this refer the http://www.idyllic-software.com/blog/creating-pdf-using-prawn-in-ruby-on-rails/
you can find easy solution..
Upvotes: 2
Reputation: 8516
Try removing the whole respond_to
block, so you will have:
def download_report
@downloads = StatisticDownload.select("date(Date) as downloaded_date, count(id) as count").where("DownloadSuccess=?","1").group("date(Date)")
end
Alternatively, if you really need the respond_to block, don't specify a block after 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
In both cases, I'm guessing you need to let prawnto's controller magic take over.
Upvotes: 0