I have been having problems when using pagination along with named scope. The second page or any consecutive page of pagination using named_scope still returns result from the first page. Using find(:all) returns the pagination result correctly. Has anyone been able to use both them both correctly or experienced the same problem?
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 }