From 33d2d098f18f06d107f717f715fe5ce9796aeb02 Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Mon, 16 Dec 2024 17:46:01 -0600 Subject: [PATCH] Wire up comment deletion --- app/controllers/comments_controller.rb | 7 ++++++- app/models/concerns/messageable.rb | 2 +- app/views/comments/edit.html.erb | 10 +++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 1746763b4..ab1404cfb 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,6 +1,6 @@ class CommentsController < ApplicationController include BubbleScoped, BucketScoped - before_action :set_comment, only: [ :show, :edit, :update ] + before_action :set_comment, only: [ :show, :edit, :update, :destroy ] def create @bubble.capture new_comment @@ -18,6 +18,11 @@ class CommentsController < ApplicationController render :show end + def destroy + @comment.destroy + redirect_to @bubble + end + private def comment_params params.require(:comment).permit(:body) diff --git a/app/models/concerns/messageable.rb b/app/models/concerns/messageable.rb index 1005f5492..723be91d2 100644 --- a/app/models/concerns/messageable.rb +++ b/app/models/concerns/messageable.rb @@ -4,7 +4,7 @@ module Messageable TYPES = %w[ Comment EventSummary ] included do - has_one :message, as: :messageable, touch: true + has_one :message, as: :messageable, touch: true, dependent: :destroy has_one :bubble, through: :message end end diff --git a/app/views/comments/edit.html.erb b/app/views/comments/edit.html.erb index 2df0f1e16..a4ecf07df 100644 --- a/app/views/comments/edit.html.erb +++ b/app/views/comments/edit.html.erb @@ -4,7 +4,7 @@ data: { controller: "form", action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel" } do |form| %> <%= form.text_area :body, class: "input comment__input", required: true, rows: 3 %>
- <%= form.button class: "btn btn--reversed txt-small" do %> + <%= form.button class: "btn btn--reversed txt-small", type: :submit do %> <%= image_tag "check.svg", aria: { hidden: true }, size: 16 %> Save <% end %> @@ -12,7 +12,15 @@ <%= image_tag "close.svg", aria: { hidden: true }, size: 16 %> Cancel <% end %> + + <%= tag.button type: :submit, class: "btn btn--small btn--negative flex-item-justify-end", form: dom_id(@comment, :delete_form), + data: { turbo_confirm: "Are you sure you want to delete this comment?" } do %> + <%= image_tag "remove.svg", aria: { hidden: true }, size: 16 %> + Delete + <% end %>
<% end %> + + <%= form_with url: bucket_bubble_comment_path(@bubble.bucket, @bubble, @comment), method: :delete, id: dom_id(@comment, :delete_form), data: { turbo_frame: "_top" } %> <% end %>