How to implement "top writers" table in Rails?
In my Rails 3 application users can write messages/posts in forum.
I would like to display to users "Top Writes" table, something like:
Alex - 14% (i.e. 14% of forum's content was written by Alex)
Greg - 13%
Natalie - 10%
Rachel - 8%
...
Would you store the number of characters (probably excluding punctuation) in each message in a database along开发者_如何学JAVA with other message details (and update it when message edited) ?
Would you store the number of characters that each user wrote along with other user details (and update this number once user adds / deletes / updates a message) ?
Would you store the total number of characters in the database (i.e. the sum of all numbers from
2.
?Would you store the percentages that are going to be displayed (and update them accordingly) ?
I would focus on a metric that rewards good content, not just content. Stack Overflow is a good example of this --- you get rewarded when your peers value your content.
For your specific question:
- Add columns on each Message: content-length
- Add a column on each User: total-content-length
- When you save a new message, recaculate total-content-length for the user (sum of all message.content-length)
The percentage based table at that point is fairly simple
精彩评论