Ruby on rails 3 使用Prawn gem生成pdf的Ruby on rails应用程序在呈现时出错:未定义的方法`text';零级:零级
控制器中的代码Ruby on rails 3 使用Prawn gem生成pdf的Ruby on rails应用程序在呈现时出错:未定义的方法`text';零级:零级,ruby-on-rails-3,prawn,Ruby On Rails 3,Prawn,控制器中的代码 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 已创建视图 # dow
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会生成一个错误:
你有一个零的对象,当你没有想到它!
您可能期望数组的一个实例。
计算nil.map时出错
我已经安装了prawn 0.12.0和prawnto。尝试删除整个
respond\u to
块,这样您就可以:
def download_report
@downloads = StatisticDownload.select("date(Date) as downloaded_date, count(id) as count").where("DownloadSuccess=?","1").group("date(Date)")
end
或者,如果您确实需要respond\u块,请不要在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的控制器magic接管
你可以找到简单的解决办法