Remove Poll::Voter record when there is no more user answers
Now we can remove answers we should provide a way of removing voting.
This commit is contained in:
@@ -5,7 +5,7 @@ class Polls::AnswersController < ApplicationController
|
||||
through_association: :answers
|
||||
|
||||
def destroy
|
||||
@answer.destroy!
|
||||
@answer.destroy_and_remove_voter_participation
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
|
||||
@@ -23,6 +23,16 @@ class Poll::Answer < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_and_remove_voter_participation
|
||||
transaction do
|
||||
destroy!
|
||||
|
||||
if author.poll_answers.where(question_id: poll.question_ids).none?
|
||||
Poll::Voter.find_by(user: author, poll: poll, origin: "web").destroy!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def max_votes
|
||||
|
||||
Reference in New Issue
Block a user