Instantly share code, notes, and snippets.

Embed
What would you like to do?
will_paginate query with per_page working in rails3
@articles = Article.
select('articles.*, (SUM(votes.vote = 1)/COUNT(votes.vote)) votes_ratio, COUNT(votes.vote) votes_num').
joins(:votes).
group('articles.id').
having('votes_num >= 5 AND votes_ratio >= 0.8').
order('votes_ratio DESC, votes_num DESC').
paginate(:page => params[:page], :per_page => Article.per_page)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment