PaymentsController中的NoMethodError#summary,undefined方法`empty?'为零:NilClass

时间:2015-07-08 12:35:07

标签: ruby-on-rails

我收到以下错误:

  

PaymentsController中的NoMethodError#summary

     

未定义的方法`空?为零:NilClass   提取的来源(第134行):

132    format.pdf do
133    pdf = SummaryPdf.new(@klasses)
134    send_data pdf.render, filename: "Payments Summary_#{AcademicTerm.current.details}.pdf", type: "application/pdf"
135   end
136 end
137end

SummaryPdf是一个负责打印学校付款收入摘要的班级。它在支付控制器下定义为

def summary
  @klasses = Klass.all
  respond_to do |format|
    format.html {render "summary"}
    format.pdf do
      pdf = SummaryPdf.new(@klasses)
      send_data pdf.render, filename: "Payments Summary_#{AcademicTerm.current.details}.pdf", type: "application/pdf"
    end
  end
end

的routes.rb

resources :payments do
  get 'search_form', :on=>:collection
  get 'klass_menu',:on =>:collection
  get 'byklass',:on =>:collection
  get 'enrolment',:on =>:collection
  get 'bystudent',:on =>:collection
  get 'with_balance', :on=>:collection
  get 'fully_paid', :on=>:collection
  get 'all_with_balance', :on=>:collection
  get 'all_fully_paid', :on=>:collection
  get 'summary', :on=>:collection

那么,谁能帮我解决这个问题?

1 个答案:

答案 0 :(得分:0)

不知道render方法在第134行上完全做了什么,但您确定可以在未保存的SummaryPdf对象上调用它吗?我说render方法需要一个已保存的实例。