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)는 will_paginate에 항상 < = per_page입니다.
나는 이것이 왜 그런지 이해하지만, 쿼리를 두 번 실행하지 않고서는 will_paginate와 한 번만 실행하면됩니다.
훌륭하게, 감사합니다. 그래서 허용 할 때 9 분에 동의합니다 –
걱정하지 마십시오 .. :) –
불행히도 그 두 번째 SQL 쿼리, 그게없이 그것을 할 방법을 의미합니까? – bcackerman