简体   繁体   English

Rails 4:使用merit gem创建点规则

[英]Rails 4: Creating point rules using merit gem

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. 我正在将我的应用程序的投票和声誉系统从activerecord-reputation-system转换优点,因为后者似乎有一个更活跃的核心团队。

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: 从merit关于点规则的自述部分,我看到了这个例子:

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

My understanding is that :reviewer and reviewed in this example are the ones that get the points allocated to them. 我的理解是:reviewer在这个例子中, reviewed :reviewerreviewed者可以获得分配给他们的分数。 However, when I try this in my own point_rules.rb: 但是,当我在自己的point_rules.rb中尝试这个时:

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

I get the following error: 我收到以下错误:

[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? 我知道我在这里遗漏了一些东西,但有人可以告诉我它是什么吗?

This code works for my project using merit. 此代码适用于我的项目使用优点。

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

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

I used both because I'm not sure how to combine them. 我使用了两者,因为我不确定如何将它们组合起来。 My app involves votes on comments, and the voter will receive 10 points for voting on the comment and the comment owner also receives 10 points. 我的应用程序涉及评论投票,选民将获得10分投票评论,评论所有者也获得10分。

Hope this helps. 希望这可以帮助。

Merit works like this: 功绩如下:

If you define a rule without specify to whom, the points will be assigned to current_user by default 如果您定义的规则未指定给谁,则默认情况下会将这些点分配给current_user

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

If you want to assign points to an user outside of current_user, specify it 如果要为current_user之外的用户分配点,请指定它

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

In above example, :user refers to method question.user , who is the author of the question, different from current_user who voted this. 在上面的示例中, :user指的是方法question.user ,它是question.user的作者,不同于对其进行投票的current_user。

In OP's case, actually ActiveRecord Reputation and Merit are for different purpose and can't be fully interchanged. 在OP的情况下,实际上ActiveRecord声誉和Merit用于不同的目的,不能完全互换。

  1. ARP can be used on all models, including users and non-users. ARP可用于所有型号,包括用户和非用户。 Meirt is for user only. Meirt仅供用户使用。

  2. Merit has another module for badge. Merit还有另一个徽章模块。 ARP doesn't. ARP没有。

  3. Merit has a Rule module where you can define all rules in one place, like CanCan. Merit有一个Rule模块,您可以在一个地方定义所有规则,如CanCan。 While in ARP there is no such place. 在ARP中没有这样的地方。

  4. You'll deal with models mainly in ARP. 你将主要在ARP中处理模型。 In Merit, you'll work with both Controller and Model. 在Merit中,您将使用Controller和Model。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM