我一直在使用分頁和命名範圍時遇到問題。 使用named_scope的第二頁或任何連續分頁頁面仍會返回第一頁的結果。 使用find(:all)可以正確返回分頁結果。 有沒有人能夠正確使用它們或遇到同樣的問題?使用will_paginate和named_scoped
class Study < ActiveRecord::Base
named_scope :opened, :conditions => {:study_stat => [205, 11203]}
end
#find(:all) returns correct studies for both pages
Study.find(:all, :conditions => {:study_stat => [205, 11203]}).paginate(:per_page => 10, :page => 1).each {|e| pp e.study_number }
Study.find(:all, :conditions => {:study_stat => [205, 11203]}).paginate(:per_page => 10, :page => 2).each {|e| pp e.study_number }
#using named_scope returns correct result for the first page but the second page has the same studies as ones in the page one.
Study.opened.paginate(:per_page => 10, :page => 1).each {|e| pp e.study_number }
Study.opened.paginate(:per_page => 10, :page => 2).each {|e| pp e.study_number }
謝謝。我嘗試過但仍然沒有運氣。一個有趣的部分可能是它返回了正確數量的結果。因此,如果第2頁返回3項研究,則會顯示首頁的前三項研究。 – achristoph 2009-09-21 16:30:00