Allow undo votes in comments votes component

This commit is contained in:
taitus
2023-09-20 16:10:36 +02:00
parent f87a332c3e
commit 718fcba6d8
16 changed files with 101 additions and 36 deletions

View File

@@ -1,7 +1,8 @@
module Comments
class VotesController < ApplicationController
load_and_authorize_resource :comment
before_action :authenticate_user!
load_and_authorize_resource :comment
load_and_authorize_resource through: :comment, through_association: :votes_for, only: :destroy
before_action :verify_comments_open!
def create
@@ -13,6 +14,14 @@ module Comments
end
end
def destroy
@comment.unvote_by(current_user)
respond_to do |format|
format.js { render :show }
end
end
private
def verify_comments_open!