2013-06-22 27 views
0

我正在研究一個在用戶數據庫上進行搜索的rails應用程序。由於搜索相當複雜,我有一個搜索模型,它將不同的搜索參數和結果方法存儲在該模型中,實際上將查詢放在一起並返回一個對象數組。will_paginate在對象上的方法結果

由於搜索與結果中返回的對象之間沒有關係,是否仍然可以使用will_paginate對結果進行分頁?我是否以這種錯誤的方式去做?

回答

0

應該可以做你做的事情,而不需要分頁數組。根據文檔:

# paginate in Active Record now returns a Relation 
Post.where(:published => true).paginate(:page => params[:page]).order('id DESC') 

# the new, shorter page() method 
Post.order('created_at DESC').page(params[:page]) 

((從https://github.com/mislav/will_paginate/wiki))

...所以你應該能夠建立你的「裏」,甚至作爲一個模型的方法,然後分頁模型方法的結果。

可以分頁陣列,如果你絕對有必要,根據這些指令:

https://github.com/mislav/will_paginate/wiki/Backwards-incompatibility#willpaginatecollection