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 %>