当前位置: 动力学知识库 > 问答 > 编程问答 >

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%

...

  1. Would you store the number of characters (probably excluding punctuation) in each message in a database along with other message details (and update it when message edited) ?

  2. 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) ?

  3. Would you store the total number of characters in the database (i.e. the sum of all numbers from 2. ?

  4. 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:

  1. Add columns on each Message: content-length
  2. Add a column on each User: total-content-length
  3. 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

分享给朋友:
您可能感兴趣的文章:
随机阅读: