4

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]

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 

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?

dmanaster
  • 579
  • 1
  • 6
  • 16

2 Answers2

3

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.

Hope this helps.

Justin
  • 4,922
  • 2
  • 27
  • 69
  • Thanks for sharing your code, @Justin. This is working for me as you described - the voter and the owner of the question are getting 10 points each. I'm trying to get the question itself to get 10 points instead of the voter. Do you know how to designate that? – dmanaster Dec 18 '13 at 02:50
  • Ohhh, I'm sorry I must have misunderstood the question. Well I haven't tried this, but i'd suspect you'll have run this for Question - `rails g merit MODEL_NAME`, make sure the model `has_merit`, and in the point_rules.rb - `score 10, :on => 'questions#vote', to: [:user, :question]`. I haven't tested this though. – Justin Dec 18 '13 at 02:59
  • I am going to test it now and will get back to you if you haven't found the answer yet. – Justin Dec 18 '13 at 03:03
  • I did run `rails g merit MODEL_NAME` and the model already `has_merit`. When I try `score 10, :on => "questions#vote", to: [:user, :question]` it gets me the same error as before - `[merit] NoMethodError on Question#question (called from Merit::TargetFinder#other_target)`. – dmanaster Dec 18 '13 at 03:09
3

Merit works like this:

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

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

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.

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

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

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

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

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

Billy Chan
  • 24,625
  • 4
  • 52
  • 68
  • Thanks, Billy. This seems like the definitive answer I was looking for. Are there any plans to extend merit beyond users? This seems like it would be a common use case. – dmanaster Dec 18 '13 at 14:10
  • @DavidManaster, my pleasure to be a bit of help. Tute is the man who wrote this awesome gem, not me:) I'm just an user. But I don't think it's likely the objective models will get points in the future. After all Merit is not for points only, but for both points and badge, which can only apply to users. – Billy Chan Dec 18 '13 at 15:11