Created
January 21, 2011 16:27
-
-
Save sobstel/789923 to your computer and use it in GitHub Desktop.
will_paginate query with per_page working in rails3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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