Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: Default will_paginate to last page of results

Is there an easy way, to default will_paginate to last page? I would like to show user latest addition and allow to browse previuos pages of results...

like image 417
mdrozdziel Avatar asked Nov 06 '22 09:11

mdrozdziel


2 Answers

Just order your query so that it's in reverse chronological order.

Post.paginate(:page => (params[:page] || 1), :per_page => 20 :order => "created_at desc")
like image 128
Chris Heald Avatar answered Nov 09 '22 15:11

Chris Heald


The proper way to do it is to reverse the sorting order, i.e. add

    :order => 'created_at DESC'

to your paginate call. User would expect the "latest addition" on the beginning, and older ones on the following pages.

like image 45
qertoip Avatar answered Nov 09 '22 15:11

qertoip