views:

154

answers:

3

I'm creating a digg-like site using Ruby on Rails that ranks the item (based on this algorithm). I'm using the will-paginate gem list the items in pages.

The problem is, will-paginate only allows me to insert ':order =>' based on the table data. I would like to make will-paginate to sort by a number which is calculated using a function based on different fields on the table (e.g number of votes, age hours).

How can I do that?

A: 

According to the comments/documentation in the code, you can use

Post.paginate_by_something

in order to use

Post.find_all_by_something

to get the collection of items you want to use paginate for. The :order option is required to set the order of the items.

So for your problem you can create a custom find method, adding a rank column using your algorithm. Use the :order option to sort on this ranking.

Veger
A: 

You can also use the paginate method on named scopes. If you make a scope for the ordering you could just do Article.ordered.paginate.

nc
A: 

sorry, I cannot help I am afraid Services

services