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)