Rails 3 Sorting Submissions by most recently popular
I hav开发者_StackOverflow社区e a site that has user submissions that users can vote on. I want to be able to organize these submissions on my homepage in a variety of fashions, but the most complex one is the "Currently Popular". I assume the best way to go about this is named scopes, but I'm not exactly sure how to do it.
Each submission has the attributes: votes_up:integer
, and votes_down:integer
I think the best way to do this will be to find the ratio of votes_up / (votes_up + votes_down)
, all within the last day. I additionally have a Votes model that has: submission_id, vote_type ("up" or "down"), and user_id
. Obviously both submissions and votes have created_at:datetimes
I think it would be better if it returned results that had a large quantity of votes in the last 1 day, rather than submissions that are from the last 1 day (that way submissions that take time to gather steam can still qualify)
How would I structure a query that will return submissions in this order with the date limitations?
Does this make sense?
thanks!
Popular with whom? With a / a + b you'll get a lot of noise when you have just a handful of votes, and when you have a controversial subject the votes won't at all reflect the quality of the material. People take sides and engage in politics, and people with bad opinions will tend to vote way too much.
The theoretically ideal way to deal with this is to highlight content that someone the user usually agrees with endorses and hide the stuff from people who they disagree with. A special list can have the most controversial subjects. This approach can be resource intensive, and I don't know how well Ruby on Rails does database optimization.
May I suggest using vote_fu and seeing if recent karma satisfies your need?
精彩评论