This commit is contained in:
r888888888
2013-04-18 00:04:51 -07:00
parent 53ee04d6a2
commit 36bbda3d45
5 changed files with 24 additions and 30 deletions

View File

@@ -527,8 +527,8 @@ class Post < ActiveRecord::Base
def add_favorite!(user)
return if favorited_by?(user.id)
append_user_to_fav_string(user.id)
increment!(:fav_count)
increment!(:score) if CurrentUser.is_privileged?
Post.connection.execute_sql("update posts set fav_count = fav_count + 1 where id = #{id}")
Post.connection.execute_sql("update posts set score = score + 1 where id = #{id}") if CurrentUser.is_privileged?
user.add_favorite!(self)
end
@@ -538,8 +538,8 @@ class Post < ActiveRecord::Base
def remove_favorite!(user)
return unless favorited_by?(user.id)
decrement!(:fav_count)
decrement!(:score) if CurrentUser.is_privileged?
Post.connection.execute_sql("update posts set fav_count = fav_count - 1 where id = #{id}")
Post.connection.execute_sql("update posts set score = score - 1 where id = #{id}") if CurrentUser.is_privileged?
delete_user_from_fav_string(user.id)
user.remove_favorite!(self)
end
@@ -597,7 +597,7 @@ class Post < ActiveRecord::Base
module VoteMethods
def can_be_voted_by?(user)
!votes.exists?(["user_id = ?", user.id])
!PostVote.exists?(:user_id => user.id, :post_id => id)
end
def vote!(score)
@@ -612,6 +612,7 @@ class Post < ActiveRecord::Base
votes.create(:score => score)
else
puts "raising"
raise PostVote::Error.new("You have already voted for this post")
end
end