Rails 4:使用优点宝石创建点规则 [英] Rails 4: Creating point rules using merit gem

查看:122
本文介绍了Rails 4:使用优点宝石创建点规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 activerecord-reputation-system 改为优点,因为后者似乎拥有更加活跃的核心团队.

I am in the process of converting my app's voting and reputation system from activerecord-reputation-system to merit because the latter seems to have a much more active core team.

我正在尝试建立积分规则,以便对我的应用程序中的问题和答案进行投票.理想情况下,当用户对问题进行投票时,规则将为问题本身以及问题的创建者分配分数.

I'm attempting to establish point rules for voting on questions and answers in my app. Ideally, when a user votes up a question, the rule would allocate points to the question itself, and also to the question's creator.

积分规则的功绩自述部分中,我看到了以下示例:

From merit's readme section on point rules, I see this example:

score 15, on: 'reviews#create', to: [:reviewer, :reviewed]

我的理解是,本示例中的:reviewerreviewed是获得分配给它们的点的.但是,当我在自己的point_rules.rb中尝试此操作时:

My understanding is that :reviewer and reviewed in this example are the ones that get the points allocated to them. However, when I try this in my own point_rules.rb:

score 10, :on => 'questions#vote', :to => :question 

我收到以下错误:

[merit] NoMethodError on `Question#question` (called from Merit::TargetFinder#other_target)

我知道我在这里丢失了一些东西,但是有人可以告诉我它是什么吗?

I know that I am missing something here, but can someone please tell me what it is?

推荐答案

优点如下:

如果您在定义规则时未指定谁,则默认情况下会将这些点分配给current_user

If you define a rule without specify to whom, the points will be assigned to current_user by default

score 15, on: 'reviews#create' # This is for current_user

如果要为current_user以外的用户分配点,请指定

If you want to assign points to an user outside of current_user, specify it

score 10, :on => 'questions#vote', to: :user

在上面的示例中,:user引用方法question.user,该方法的作者是问题的作者,与对该问题进行投票的current_user不同.

In above example, :user refers to method question.user, who is the author of the question, different from current_user who voted this.

在OP的情况下,实际上ActiveRecord信誉和优点是出于不同的目的,不能完全互换.

In OP's case, actually ActiveRecord Reputation and Merit are for different purpose and can't be fully interchanged.

  1. ARP可以在所有型号上使用,包括用户和非用户. Meirt仅供用户使用.

  1. ARP can be used on all models, including users and non-users. Meirt is for user only.

功绩还有另一个用于徽章的模块. ARP没有.

Merit has another module for badge. ARP doesn't.

Merit有一个Rule模块,您可以在其中定义所有规则,例如CanCan.在ARP中没有这样的地方.

Merit has a Rule module where you can define all rules in one place, like CanCan. While in ARP there is no such place.

您将主要在ARP中处理模型.在Merit中,您将同时使用Controller和Model.

You'll deal with models mainly in ARP. In Merit, you'll work with both Controller and Model.

这篇关于Rails 4:使用优点宝石创建点规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆