views:

28

answers:

1

Is there a way in Rails (using will_paginate or any other kind of pagination) to paginate by a method?

For example, I have a Movie table, associated with user ratings. I want to be able to paginate the movies based on the mean or standard deviation of the ratings (which are defined in methods in the Movie class, not as part of the database).

How do I do this?

+1  A: 

Hi,

May be what you can do is prepare the array based on mean or standard deviation of the ratings and then use pagination on the array, like:-

@result.paginate(:page => params[:page], :per_page => 10)

Thanks, Anubhaw

Anubhaw
I don't quite follow -- is @result just an array containing the means/standard deviations? If so, how do I associate @result with the rest of the movie information (e.g., title of the movie)?
grautur
Ah, nevermind, I see -- I simply sort all my movies myself (e.g., movies.sort_by{ |m| m.rating_mean }), and paginate won't try to do anything funky if I don't specify an order.
grautur