百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

activerecord-reputation-system

> 编程语言
开源

Rails 中的主动记录声誉系统

1.3K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Rails 中的主动记录声誉系统

ActiveRecord Reputation System

The Active Record Reputation System helps you build the reputation system for your Rails application. It allows Active Record to have reputations and get evaluated by other records. This gem allows you to:

  • define reputations in easily readable way.
  • integrate reputation systems into applications and decouple the system from the main application.
  • discover more about your application and make better decisions.

Installation

  • If you are updating to version 2 from version older, you should check out migration guide.

  • For Rails 3 use versions 2.0.2 and older.

Add to Gemfile:

gem 'activerecord-reputation-system'

Run:

bundle install
rails generate reputation_system
rake db:migrate
  • Please do the installation on every upgrade as it may include new migration files.

Quick Start

Let's say we want to keep track of user karma in Q&A site where user karma is sum of questioning skill and answering skill. Questioning skill is sum of votes for user's questions and Answering skill is sum of average rating of user's answers. This can be defined as follow:

class User  [
          { :reputation => :questioning_skill, :weight => 0.8 },
          { :reputation => :answering_skill }]

  has_reputation :questioning_skill,
      :source => { :reputation => :votes, :of => :questions }

  has_reputation :answering_skill,
      :source => { :reputation => :avg_rating, :of => :answers }
end

class Answer  :author

  has_reputation :avg_rating,
      :source => :user,
      :aggregated_by => :average,
      :source_of => [{ :reputation => :answering_skill, :of => :author }]
end

class Question  :user
end

Once reputation system is defined, evaluations for answers and questions can be added as follow:

@answer.add_evaluation(:avg_rating, 3, @user)
@question.add_evaluation(:votes, 1, @user)

Reputation value can be accessed as follow:

@answer.reputation_for(:avg_rating) #=> 3
@question.reputation_for(:votes) #=> 1
@user.reputation_for(:karma)

You can query for records using reputation value:

User.find_with_reputation(:karma, :all, { :condition => 'karma > 10' })

You can get source records that have evaluated the target record:

@question.evaluators_for(:votes) #=> [@user]

You can get target records that have been evaluated by a given source record:

Question.evaluated_by(:votes, @user) #=> [@question]

To use a custom aggregation function you need to provide the name of the method on the :aggregated_by option, and implement this method on the model. On the example below, our aggregation function sums all values and multiply by ten:

…

Documentation

Please refer Wiki for available APIs and more information.

Authors

Katsuya Noguchi

  • http://twitter.com/kn
  • http://github.com/kn

Related Links

  • RailsCasts: http://railscasts.com/episodes/364-active-record-reputation-system
  • Inspired by "Building Web Reputation Systems" by Randy Farmer and Bryce Glass

Versioning

For transparency and insight into our release cycle, releases will be numbered with the follow format:

..

And constructed with the following guidelines:

  • Breaking backwards compatibility bumps the major
  • New additions without breaking backwards compatibility bumps the minor
  • Bug fixes and misc changes bump the patch

For more information on semantic versioning, please visit http://semver.org/.

License

Copyright 2012 Twitter, Inc.

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言