Post#unvote!: Return correct score (fixes #2709).

vote.destroy sets the score in the database but not on the in-memory
post. So just reload the post from the db to get the updated score,
don't duplicate the logic of setting it again.
This commit is contained in:
evazion
2016-10-08 09:07:41 +00:00
parent cc7d76b168
commit 3838167dc0
2 changed files with 17 additions and 6 deletions

View File

@@ -1033,11 +1033,7 @@ class Post < ActiveRecord::Base
vote = PostVote.where("post_id = ? and user_id = ?", id, CurrentUser.user.id).first
vote.destroy
if vote.score > 0
self.score -= vote.score
else
self.score += vote.score
end
self.reload
end
end
end