简体   繁体   English

使用will_paginate从Rails查询获取总结果计数

[英]Getting total result count from Rails query using will_paginate

I get a list of objects from my Rails app, and use will_paginate to page as usual, and then I have a little method used to save details of the search to the database: 我从我的Rails应用程序中获取了一个对象列表,并像往常一样使用will_paginate页面,然后我有一个方法用于将搜索的详细信息保存到数据库:

per_page=10
session[:search_params] = params[:search_people]
@documents = Person.search_people(params[:search_people], params[:page], per_page)

Search.create(:user_id     => (!current_user ? 0 : current_user.id),
   :search_type => "Person", 
   :firstname   => params[:search_people][:first_name], 
   :lastname    => params[:search_people][:last_name],
   :results     => @documents.count )

The problem is, the number of search results (@douments.count) is always <= per_page used for will_paginate. 问题是,搜索结果的数量(@douments.count)总是<= per_page用于will_paginate。

I understand why this is, but is there a way around it without running the query twice, once with will_paginate and once without? 我明白为什么会这样,但有没有办法绕过它而不运行两次查询,一次使用will_paginate而一次没有?

尝试<%=@documents.total_entries%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM