开发者

Using Scope in Kaminari

I'm trying to use Kaminari开发者_开发百科 to paginate a model. However, I'm using scope in my model which throws some error.

undefined method `to_sym' for 1:Fixnum

My scope:

scope :my_scope, select('DISTINCT(rank), COUNT(rank) no_rank').group(1).order('2 DESC')

In my controller:

@users = User.my_scope.page(params[:page])


Found the answer myself.

Changed my scope to:

scope :my_scope, select('DISTINCT(rank), COUNT(rank) no_rank').group('rank')

and in my controller

@users = User.my_scope.order('rank DESC').page(params[:page])


Are you missing a @users = User.my_scope.all.page(params[:page]) or something? Actually, wouldn't group 1 return one record and you wouldn't have to paginate it? Is this the real query?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜