Ruby on Rails-虾&虾错误

发布于 2024-12-21 08:48:42 字数 1524 浏览 5 评论 0原文

在 ruby​​ on Rails 应用程序 prawn 中,prawnto 用于生成 pdf 会引发一些错误。generate_report.pdf.prawn

 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 

/admin/generate_report中的代码

        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.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

我该如何纠正这个错误错误

In a ruby on rails application prawn ,prawnto is used to generate pdf raises some error..

 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 

Code in 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 gives a blank page as output

/admin/generate_report.pdf gives 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
  Extracted source (around line #2):

     1: pdf.move_down(30) 
      2: book =  @downloads.map do |item|
      3:  [
    4:   item.downloaded_date,
     5:   item.count

how can i rectify this error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找一个思念的角度 2024-12-28 08:48:42

可能值得去 http://railscasts.com/episodes/153-pdfs- with-prawn-revised 并按照教程进行操作,如果您还没有订阅专业版,则必须订阅才能观看。

May be worth going to http://railscasts.com/episodes/153-pdfs-with-prawn-revised and following the tutorial, you will have to subscribe to watch if you haven't got a pro subscription though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文