因为 Kaminari 使用的必须是 ActiveRecord 对象,一开始报了个错,半天搞不懂,回头自己重新查询了一下资料,其实官方的 Github 上就已经写好了。

把代码贴出来一下其实挺简单的:

def index
user_name
= params[:user_name]
tempSQL = "select o.*,u.user_name,u.nick_name,u.phone,f.title from
orders o, users u, flies f where o.user_id = u.id and o.goods_id = f.id"
if
!user_name.nil?
puts 'run here'
tempSQL += " and u.user_name = '#{user_name}'"
end
@orders
= Kaminari.paginate_array(Order.find_by_sql(tempSQL)).page(params[:page])
end

Kaminari.paginate_array 中已经就能够完成转换功能了,大家继续,玩得开心哦。