An existing array vparray
is being generated, then sorted by a non-db column rate
. It then needs to be paginated :
@vps = vparray.sort_by{|e| e.rate}
@vps = WillPaginate::Collection.create(1, 10, @vps.length) do |pager|
pager.replace @vps
end
The view;
<%= will_paginate @vps, :previous_label => "prev ", :next_label => " next" -%>
renders fine, the number of pages pans out and the page is apparently the first. However, upon: <% @vps.each do |product| %>
, the entire
sorted array is being rendered.
Apparently, the array can only be populated with values of current page. However
@vps = vparray.sort_by{|e| e.rate}
@vps = @vps.paginate(:page => params[:page], :per_page => 10)
@vps = WillPaginate::Collection.create(1, 10, @vps.length) do |pager|
pager.replace @vps
end
is incorrect. The paginate command actually reduces the found set to the same number as per_page and therefore == only 1 page!
So I'm assuming that line should not be there. The view should be calling the proper page of results
<% @vps.each do |product| %>
something better than
<% @vps.page(params[:page]).each do |product| %>
that generates undefined method
page for WillPaginate::Collection`
context: ruby 1.9.3, rails 3.2.17, will_paginate 3.0.5