2013-01-18 49 views
24

我從Rails應用程序中獲取對象列表,並使用will_paginate作爲平常頁面,然後使用一些方法將搜索詳細信息保存到數據庫:使用will_paginate從Rails查詢中獲取總計結果數

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) 

問題是,搜索結果數量(@ douments.count)永遠是< = per_page用於will_paginate。

我明白這是爲什麼,但有沒有辦法解決這個問題,而無需兩次運行查詢,一次使用will_paginate,一次沒有?

回答

62

嘗試<%[email protected]_entries%>

+0

輝煌,謝謝。將在9分鐘內接受,當SO允許時 –

+0

無後顧之憂.. :) –

+0

不幸的是,這意味着第二次SQL查詢,有沒有辦法做到這一點? – bcackerman