I am working on a Rails project that has pagination set up for venues (through thinking sphinx), and I am trying to set it up for users. I tried to mimic the functionality of venues as closely as I could. The problem I am running into is I am only getting back the number of results specified by :per_page instead of the total results for the query. If I increase :per_page to more then the total results, I get all of them to show up and the number links for pagination but they don't work.
In my controller I am doing
@gender = params[:user][:gender] unless params[:user].blank?
@ethnicity = params[:user][:ethnicity] unless params[:user].blank?
@age = params[:user][:age] unless params[:user].blank?
@page = params[:page].blank? ? 1 : params[:page]
@users = User.matches_for_admin({
:gender => @gender,
:ethnicity => @ethnicity,
:age => @age,
:relationship => @relationship,
:per_page => 20,
}, @page)
@pages = @users[:count] / 20 + ((@users[:count] % 20) > 0 ? 1 : 0)
if I set the :per_page to 200 I get all my results, and links come up for the pages (for pagination) but the links don't work because the per_page is higher then the total results.
This is the helper function I am using for pagination
def pagination_user(current_page, pages)
return if pages == 0
render :partial => 'pagination_user', :locals => { :current_page => current_page.to_i, :pages => pages }
end
And this is the partial that sets up the number links
<div class="fullWidthPanel lightFilter pagination">
<ul>
<li> Pages: </li>
<% (1..pages).each do |page| %>
<li>
<% if page == current_page %>
<%= page %>
<% else %>
<a href="<%= url_for_user_page page %>">
<%= page %>
</a>
<% end %>
</li>
<% end %>
</ul>
<span class="results">
<strong>
Showing results <%= 1 + (current_page-1)*20 %>
to <%= [current_page*20, @users[:count]].min %>
of <%= @users[:count] %>
</strong>
</span>
</div>
Where url_for_user_page just sets up the url to have the search options for the pagination to work.
I am new with thinking sphinx and I am confused why it is working for venues and not users when I have them set up the same. It seems like the amount of results I get are based on the :per_page attribute, instead of the number of results I actually get back from the query. Any insight into what potential issues I may be having or something I am over looking would be appreciated.
Thanks,
Alan