@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.
@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.
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: kaminari github
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.