logesh
logesh

Reputation: 2662

will_paginate render all the values if page and per_page is not sent

I use will_paginate to get the values in paging. consider the example

if params[:page] || params[:per_page]
    @users = User.paginate(:page => params[:page], :per_page 
    => params[:per_page]).all(:order => 'id ASC')
else
    @users = User.all(:order => 'id ASC')
end

format.json {
 render json: 
      {:users => @users, :current_page => @users.current_page, 
       :total_pages => @users.total_pages, 
       :total_entries => @users.total_entries
      }
}

if i did not send any parameter( params[:page] or params[:per_page] ) then it shows

NoMethodError (undefined method `current_page' for #<Array:0x000002345ab655>)

Upvotes: 2

Views: 4366

Answers (1)

sjain
sjain

Reputation: 23344

Try:

User.paginate(:page => params[:page], :per_page => User.count)

NOTE:

It will put all the users in one page and thus it will obstruct the significance of
Pagination. But if this is all you want, it is for you.

Upvotes: 1

Related Questions