雖然在一個應用程序我得到這個工作的錯誤:不能轉換成枚舉器陣列
can't convert Enumerator into Array
這裏是我的代碼,mr_collection
是MongoID查詢。
mr_collection = self.where(query).map_reduce(map, reduce).finalize(finalize).out({:replace => 'mr_results'})
paginator = WillPaginate::Collection.new(page, limit, collection_count)
collection = mr_collection.find(
:sort => sort,
:limit => limit,
:skip => skip
)
paginator.replace(collection)
儘管取得mr_collection
,如果我檢查結果mr_collection
給我:
[
{"_id"=>1.0, "value"=>{"s"=>4.2, "p"=>14.95, "pml"=>0.01993}},
{"_id"=>2.0, "value"=>{"s"=>3.7, "p"=>12.9, "pml"=>0.0172}},
{"_id"=>3.0, "value"=>{"s"=>4.2, "p"=>12.9, "pml"=>0.0172}},
{"_id"=>4.0, "value"=>{"s"=>4.0, "p"=>11.95, "pml"=>0.01593}},
{"_id"=>300.0, "value"=>{"s"=>0.0, "p"=>8.95, "pml"=>0.01193}},
]
儘管取得collection
,如果我檢查結果collection
給我:
#<Enumerator: []:find({:sort=>[["value.s", :desc], ["value.pml", :asc]], :limit=>10, :skip=>0})>
我得到線路上的錯誤paginator.replace(collection)
。我正在使用Ruby 1.9.3 & Rails 3.2.6。
剛剛更新了問題 – 2012-08-09 05:04:45