开发者

show array size with will_paginate

开发者 https://www.devze.com 2022-12-25 13:30 出处:网络
I would like to retur开发者_StackOverflown the total number of results from this query: @users = User.paginate(:page => params[:page], :per_page => 2)

I would like to retur开发者_StackOverflown the total number of results from this query:

@users = User.paginate(:page => params[:page], :per_page => 2)

@users.size simply gives me the number of results on a page. If page 1 has 2 users, then @users.size will be 2. If page 2 has 1 user, then @users.size will be 1.

How can I show the size of all the users?


will_paginate adds some attributes to the returned collection one of them is total_entries which is the total number of results the query would have returned.


You need to call another Active Record model, named count as such:

@count = User.count
0

精彩评论

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