Here is a simple plan. First, add a score
column to your users
table.
In your User
model:
after_invitation_accepted :increment_score_of_inviter
def increment_score_of_inviter
invitation_by.increment!(:score, 10)
end
def comment_vote_count
Vote.find(comment_ids).count * 2
end
def calculated_vote_count
base_score + comment_vote_count
end
def recalculate_score!
update_attribute(:score, calculated_vote_count)
end
See devise's invitation callbacks about after_invitation_accepted
This could be quite inefficient if you have a lot of voting activity, but to keep the score
column updated, add this to your Vote
model:
after_create :increment_user_score
def increment_user_score
user.increment!(:score, 2)
end
An alternative here would be to periodically recalculate the score
column, perhaps using whenever
gem:
every :hour do
User.find_each { |u| u.recalculate_score! }
end