Is that possible to use paginate with Acts_as_follower?

匆匆过客 提交于 2019-12-23 05:13:32

问题


@users = User.find_by_username(params[:username]).all_following.order("created_at DESC").paginate(page: params[:page])

This calculation won't work:(
I'd like to use pagination and order sort with acts_as_follower.


回答1:


You can pass the order (and any other option ActiveRecord#all accepts) directly to all_following like this

@users = User.find_by_username(params[:username]).all_following(:order => 'created_at DESC').paginate(page: params[:page])

UPDATE: will_paginate can paginate an array but you have to tell Rails to include this part as it's not included by default, please check this answer.




回答2:


Updated answer:

@users = User.find_by_username(params[:username]).all_following.sort_by{|i| i.created_at}
Kaminari.paginate_array(@users).page(params[:page]).per(10)

OR

Mix with Ahmad's answer

@users = User.find_by_username(params[:username]).all_following(order: 'created_at DESC')
Kaminari.paginate_array(@users).page(params[:page]).per(10)

ref: acts_as_follower github

ref: kaminari github



来源:https://stackoverflow.com/questions/13936091/is-that-possible-to-use-paginate-with-acts-as-follower

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!