mdrozdziel
mdrozdziel

Reputation: 5558

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...

Upvotes: 4

Views: 2015

Answers (3)

mdrozdziel
mdrozdziel

Reputation: 5558

This solution was the most resonable idea I found:

http://groups.google.com/group/will_paginate/browse_thread/thread/63b8d295f25085c2

Upvotes: 0

qertoip
qertoip

Reputation: 1880

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.

Upvotes: 1

Chris Heald
Chris Heald

Reputation: 62648

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")

Upvotes: 1

Related Questions