merge branch changeable-votes
This commit is contained in:
@@ -69,7 +69,41 @@ class Comment < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
module VoteMethods
|
||||
def vote!(val)
|
||||
numerical_score = val == "up" ? 1 : -1
|
||||
vote = votes.create(:score => numerical_score)
|
||||
|
||||
if vote.errors.empty?
|
||||
if vote.is_positive?
|
||||
update_column(:score, score + 1)
|
||||
elsif vote.is_negative?
|
||||
update_column(:score, score - 1)
|
||||
end
|
||||
end
|
||||
|
||||
return vote
|
||||
end
|
||||
|
||||
def unvote!
|
||||
vote = votes.where("user_id = ?", CurrentUser.user.id).first
|
||||
|
||||
if vote
|
||||
if vote.is_positive?
|
||||
update_column(:score, score - 1)
|
||||
else
|
||||
update_column(:score, score + 1)
|
||||
end
|
||||
|
||||
vote.destroy
|
||||
else
|
||||
raise CommentVote::Error.new("You have not voted for this comment")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include VoteMethods
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.user.id
|
||||
@@ -122,21 +156,6 @@ class Comment < ActiveRecord::Base
|
||||
do_not_bump_post == "1"
|
||||
end
|
||||
|
||||
def vote!(val)
|
||||
numerical_score = val == "up" ? 1 : -1
|
||||
vote = votes.create(:score => numerical_score)
|
||||
|
||||
if vote.errors.empty?
|
||||
if vote.is_positive?
|
||||
update_column(:score, score + 1)
|
||||
elsif vote.is_negative?
|
||||
update_column(:score, score - 1)
|
||||
end
|
||||
end
|
||||
|
||||
return vote
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
creator_id == user.id || user.is_janitor?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user