Ruby on rails – 搜索结果的分页

我有2个模型,post和位置,其中位置has_manypost和postbelongs_to位置。 搜索工作正常,除了total_entries之外,分页也很好。 它在结果中显示了10个以上的条目

查看search.html:

 'get' do %> 

nil %>

控制器post_controller.rb:

  def search title = params[:title] company = params[:company] location_id = params[:location_id] @posts = Post.search(title, company, location_id) end 

模型Post.rb

 def self.search(title, company, location_id) if location_id.present? paginate :conditions => ['title LIKE ? AND company LIKE ? AND location_id = ?', "%#{title}%", "%#{company}%", location_id], :per_page => 20, :order => 'created_at DESC', :page => @page, :total_entries => 10 else paginate :conditions => ['title LIKE ? AND company LIKE ?', "%#{title}%", "%#{company}%"], :per_page => 20, :order => 'created_at DESC', :page => @page, :total_entries => 10 end end 

参数:per_page定义每页上的条目计数。 :total_entries是从db中获取的条目计数。

我的意思是:per_page不能大于:total_entries