Skip to content

Instantly share code, notes, and snippets.

@sobstel
Created January 21, 2011 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sobstel/789923 to your computer and use it in GitHub Desktop.
Save sobstel/789923 to your computer and use it in GitHub Desktop.
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