In Rails console, I do:
Video.count
Returns 4
Video.limit(2)
Returns 2
v = Video.limit(2)
vv = v.page(1).per(20).count
Returns 4
Why is Kaminari displaying 4 / all records when there is a limit
being applied? Shouldn't it return 2 instead?
If you have 100 videos in the db and you want to paginate only the first 50 records, lets say 25 per page – as an idea you may limit the number of pages in the view.
# videos_controller.rb
def index
@videos = Video.page(params[:page]).per(25)
end
# index.html.erb
<%= paginate @videos, :num_pages => 2 %>
# index.html.erb using Kaminari 0.14 or higher
<%= paginate @videos, :total_pages => 2 %>
In recent versions of Kaminari (>= 0.14), :num_pages has been renamed to :total_pages. For more information, please refer to https://github.com/errbit/errbit/pull/282 and https://github.com/amatsuda/kaminari/issues/284.