change increment/decrement calls to sql
This commit is contained in:
@@ -627,11 +627,9 @@ class Post < ActiveRecord::Base
|
|||||||
def vote!(score)
|
def vote!(score)
|
||||||
if can_be_voted_by?(CurrentUser.user)
|
if can_be_voted_by?(CurrentUser.user)
|
||||||
if score == "up"
|
if score == "up"
|
||||||
increment!(:score)
|
Post.update_all("score = score + 1, up_score = up_score + 1", {:id => id})
|
||||||
increment!(:up_score)
|
|
||||||
elsif score == "down"
|
elsif score == "down"
|
||||||
decrement!(:score)
|
Post.update_all("score = score - 1, down_score = down_score - 1", {:id => id})
|
||||||
decrement!(:down_score)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
votes.create(:score => score)
|
votes.create(:score => score)
|
||||||
|
|||||||
Reference in New Issue
Block a user