簡體   English   中英

Ruby where子句返回nil對象? ActionView :: Template :: Error(nil:NilClass的未定義方法“ each”):

[英]Ruby where clause is returning nil object? ActionView::Template::Error (undefined method `each' for nil:NilClass):

我收到以下錯誤:

ActionView::Template::Error (undefined method `each' for nil:NilClass): 

這是where子句,第一個起作用。

def self.unpaid
  ARequest.where(:paid_on => nil).in(:status => [ARequest::TRANS_COMPLETE,ARequest::CANCELLED_BY]).gt(:total_owed_to_driver_in_cents => 0).asc(:assigned_driver_id).asc(:timestamp_requested)
end

這不起作用。

def self.allcall
  longtimeago = Time.now - 60.day
  yesterday = Time.now - 1.day
  ARequest.where(["paid_on >= ? AND paid_on <= ?", longtimeago.beginning_of_day, yesterday.end_of_day]).in(:status => [ARequest::TRANS_COMPLETE,ARequest::CANCELLED_BY]).gt(:total_owed => 0).asc(:assigned_driver_id).asc(:timestamp_requested)
end

上面拋出這個錯誤:

ActionView::Template::Error (undefined method `each' for nil:NilClass):

控制器代碼

def allcalls
  ensure_root
  @calls = ARequest.allcall
end

路線

get "sme/allcalls"

只是嘗試改變

where(["paid_on >= ? AND paid_on <= ?", longtimeago.beginning_of_day, yesterday.end_of_day]) 

where("paid_on >= ? AND paid_on <= ?", longtimeago.beginning_of_day, yesterday.end_of_day)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM