I am trying to paginate some items from my database however I am getting this error when I try to go onto page two of my pagination:
RangeError Exception: offset 25 and limit 25 are outside allowed range
This is the code in my controller that sets up the pagination:
@activities = (current_user.followed_users.activities(:order => [:created_at.desc]) + current_user.followed_centers.activities(:order => [:created_at.desc])).all(:limit => 40)
unless (params[:page].nil?)
@page = params[:page].to_i
end
unless (@page.nil?)
@activities = Kaminari.paginate_array(@activities).page(@page).per(10)
else
@activities = Kaminari.paginate_array(@activities).page(0).per(10)
end
I limit the amount of objects returned in my query to 40, then try to paginate the result set however I am getting a range error. I am not sure what the problem is here. If I take the limit off my initial query this works fine.
This is the output in the terminal:
RangeError (offset 25 and limit 25 are outside allowed range):
lib/ct_gems/dm-core-1.2.0/lib/dm-core/query.rb:1298:in `get_relative_position'
lib/ct_gems/dm-core-1.2.0/lib/dm-core/query.rb:592:in `slice!'
lib/ct_gems/dm-core-1.2.0/lib/dm-core/query.rb:567:in `slice'
lib/ct_gems/dm-core-1.2.0/lib/dm-core/collection.rb:1414:in `sliced_query'
lib/ct_gems/dm-core-1.2.0/lib/dm-core/collection.rb:396:in `[]'
app/controllers/users_controller.rb:64:in `stream'
lib/ct_gems/dm-core-1.2.0/lib/dm-core.rb:263:in `block in repository'
lib/ct_gems/dm-core-1.2.0/lib/dm-core/repository.rb:114:in `scope'
lib/ct_gems/dm-core-1.2.0/lib/dm-core.rb:263:in `repository'
Can anyone help please?