Wire up comment deletion

This commit is contained in:
Jason Zimdars
2024-12-16 17:46:01 -06:00
parent bcc57d66dd
commit 33d2d098f1
3 changed files with 16 additions and 3 deletions
+6 -1
View File
@@ -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)
+1 -1
View File
@@ -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
+9 -1
View File
@@ -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 %>
<div class="flex gap-half justify-start">
<%= 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 %>
<span class="for-screen-reader">Save</span>
<% end %>
@@ -12,7 +12,15 @@
<%= image_tag "close.svg", aria: { hidden: true }, size: 16 %>
<span class="for-screen-reader">Cancel</span>
<% 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 %>
<span class="for-screen-reader">Delete</span>
<% end %>
</div>
<% end %>
<%= form_with url: bucket_bubble_comment_path(@bubble.bucket, @bubble, @comment), method: :delete, id: dom_id(@comment, :delete_form), data: { turbo_frame: "_top" } %>
</div>
<% end %>