0

I am attempting to add Merit reputation system into a Rails app.

I have a votes model, and I want to award Merit points to the owners of objects that have been voted on.

#models/merit/point_rules.rb
score 2, on: 'votes#create', to: :owner_of_object_voted_on

and with

class Vote
  belongs_to :voter, class_name: 'User'
  belongs_to :votable, polymorphic: true

  def owner_of_object_voted_on
    case self.votable_type
    when 'blog_post'
      votable.owner
    end
  end
end

class BlogPost
  has_many :votes
  belongs_to :owner, class_name: 'User'
end

However, Merit is awarding points always to the current_user, rather than the object owner.

Does score to: take a symbol that represents a method on the vote model, and am I setting this up correctly?

The relevant source indicates that :action_user is being used, but I'm unclear where this is defined and whether it can be overwritten.

Andy Harvey
  • 12,333
  • 17
  • 93
  • 185
  • `to:` takes a symbol which is a method to be sent to `@vote` which ought to be defined in `VotesController#create` (https://github.com/merit-gem/merit#points). Can you post your development logs for that action? – TuteC May 05 '16 at 16:16
  • Thanks @TuteC. I've created a gist containing the log - this time for a Flag rather than Vote model, but the set up is the same. In this example current_user has ID:690, while the owner of the Asset has ID:681. I've also added relevant model code to the top of the gist for reference. please let me know if anything else is of use. https://gist.github.com/ahharvey/7650cddff50d85f48da2516f3cacaf63 – Andy Harvey May 05 '16 at 16:35
  • @TuteC just checking in whether the posted log looks OK? – Andy Harvey May 07 '16 at 08:49
  • The log looks good. Can you paste the controller code, please? Thanks! – TuteC May 09 '16 at 14:49
  • Thanks @TuteC, I've added the controller code and relevant method to the top of the gist: https://gist.github.com/ahharvey/7650cddff50d85f48da2516f3cacaf63 – Andy Harvey May 09 '16 at 23:07
  • All looks good to me. I'd need to run the app and debug myself in order to be able to triage why this might happen. If you can put it in GitHub or share it elsewhere, great. – TuteC May 10 '16 at 15:03

0 Answers0