change increment/decrement calls to sql

This commit is contained in:
r888888888
2013-05-07 13:42:58 -07:00
parent a031a4eba8
commit 1ec02dbe4b

View File

@@ -627,11 +627,9 @@ class Post < ActiveRecord::Base
def vote!(score)
if can_be_voted_by?(CurrentUser.user)
if score == "up"
increment!(:score)
increment!(:up_score)
Post.update_all("score = score + 1, up_score = up_score + 1", {:id => id})
elsif score == "down"
decrement!(:score)
decrement!(:down_score)
Post.update_all("score = score - 1, down_score = down_score - 1", {:id => id})
end
votes.create(:score => score)