注意:我正在关注此示例的http://railscasts.com/episodes/364-active-record-reputation-system。
我有一个位置模型,我让用户对该项目进行排名(即1到5星):
has_reputation:location_rating,source :: user,aggregated_by: :平均
在我的控制器中,我要删除评级:
@ location.delete_evaluation(:location_rating,current_user)
或更新它:
@ location.add_or_update_evaluation(:location_rating,params [:rating],current_user)
我对如何查询感到十分困惑:
我正在尝试@location.reputation_for(:location_rating)
并获得一些奇怪的行为。如果给定用户删除了评级,那么新的reputation_for值似乎在旧评级中取平均值。
例如:
1.9.3p0 :038 > RSEvaluation.all
RSEvaluation Load (1.7ms) SELECT "rs_evaluations".* FROM "rs_evaluations"
+----+-----------------+-----------+-------------+-----------+-------------+-------+-------------------------+-------------------------+
| id | reputation_name | source_id | source_type | target_id | target_type | value | created_at | updated_at |
+----+-----------------+-----------+-------------+-----------+-------------+-------+-------------------------+-------------------------+
| 46 | tracking | 1 | User | 6 | Location | 0.0 | 2012-08-28 05:15:13 UTC | 2012-08-28 05:15:13 UTC |
| 48 | tracking | 1 | User | 5 | Location | 0.0 | 2012-09-04 14:44:37 UTC | 2012-09-04 14:44:37 UTC |
| 51 | tracking | 1 | User | 8 | Location | 0.0 | 2012-09-12 06:51:58 UTC | 2012-09-12 06:51:58 UTC |
| 52 | tracking | 1 | User | 1 | Location | 0.0 | 2012-09-12 14:54:39 UTC | 2012-09-12 14:54:39 UTC |
| 54 | location_rating | 1 | User | 5 | Location | 3.0 | 2012-09-19 05:10:46 UTC | 2012-09-19 05:18:16 UTC |
| 56 | tracking | 11 | User | 5 | Location | 0.0 | 2012-09-19 05:47:10 UTC | 2012-09-19 05:47:10 UTC |
| 58 | location_rating | 11 | User | 3 | Location | 2.0 | 2012-09-19 06:33:12 UTC | 2012-09-19 06:33:12 UTC |
| 61 | location_rating | 11 | User | 5 | Location | 5.0 | 2012-09-19 07:15:42 UTC | 2012-09-19 07:15:42 UTC |
+----+-----------------+-----------+-------------+-----------+-------------+-------+-------------------------+-------------------------+
在位置id = 5,我的声誉不是(3 + 5)/ 2 = 4?我目前得到2.59375。我将用户11的评级更新为1,新信誉为0.59375。
我确信我在这里遗漏了一些明显的东西(因为我是Rails的新手)。
答案 0 :(得分:2)
版本2.0.0已解决此问题,因此您应该更新您的gem。