Ruby on rails RubyonRails-prawn和prawnto错误
在ruby on rails应用程序prawn中,使用prawnto生成pdf会引发一些错误Ruby on rails RubyonRails-prawn和prawnto错误,ruby-on-rails,ruby-on-rails-3,prawn,prawnto,Ruby On Rails,Ruby On Rails 3,Prawn,Prawnto,在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.wh
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
生成报告.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_报告提供一个空白页作为输出
/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
如何纠正此错误可能值得一看,在本教程之后,如果您没有专业订阅,则必须订阅watch。更改控制器中的代码,如下所示:respond_to do | format | format.pdf do render:layout=>false end end现在可以正常工作了。现在的问题是在视图上设置文件的样式,它会生成一个错误undefined method headers='for undefined method align=>'。您能告诉我为什么会发生这种情况吗?