简体   繁体   中英

Kaminari paginate array. How to handle lot of data?

I need to paginate 2 different models. That what I use now:

activity_logs = ActivityLog.for_user(@user.id)
                  .group('activity_id').not_anonymous.recent

replies = @user.posts.recently_created

@activity_logs = Kaminari.paginate_array(activity_logs + replies)
                   .page(params[:page]).per(20)

But it doesn't show replies because there is a lot of records of ActivityLog. So what can I do here?

Kaminari doesn't know to sort your two arrays by creation date. You'll need to do that yourself. Something like...

paginatable_array = (activity_logs + replies).sort_by(&:created_at)
@activity_logs = Kaminari.paginate_array(paginatable_array).page(params[:page]).per(20)

And yes, paginatable_array is a horrible choice of names. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM