diff --git a/app/controllers/simple_discussion/application_controller.rb b/app/controllers/simple_discussion/application_controller.rb index 11c3841..d9587fd 100644 --- a/app/controllers/simple_discussion/application_controller.rb +++ b/app/controllers/simple_discussion/application_controller.rb @@ -13,7 +13,7 @@ def is_moderator_or_owner?(object) helper_method :is_moderator_or_owner? def is_moderator? - current_user.respond_to?(:moderator) && current_user.moderator? + current_user.respond_to?(:moderator?) && current_user.moderator? end helper_method :is_moderator? diff --git a/app/controllers/simple_discussion/forum_threads_controller.rb b/app/controllers/simple_discussion/forum_threads_controller.rb index 6edc92d..570597a 100644 --- a/app/controllers/simple_discussion/forum_threads_controller.rb +++ b/app/controllers/simple_discussion/forum_threads_controller.rb @@ -1,7 +1,7 @@ class SimpleDiscussion::ForumThreadsController < SimpleDiscussion::ApplicationController before_action :authenticate_user!, only: [:mine, :participating, :new, :create] - before_action :set_forum_thread, only: [:show, :edit, :update] - before_action :require_mod_or_author_for_thread!, only: [:edit, :update] + before_action :set_forum_thread, only: [:show, :edit, :update, :destroy] + before_action :require_mod_or_author_for_thread!, only: [:edit, :update, :destroy] def index @forum_threads = ForumThread.pinned_first.sorted.includes(:user, :forum_category).paginate(page: page_number) @@ -60,6 +60,11 @@ def update end end + def destroy + @forum_thread.destroy! + redirect_to simple_discussion.forum_threads_path + end + private def set_forum_thread diff --git a/app/models/forum_thread.rb b/app/models/forum_thread.rb index 18ad3c7..1bc79e7 100644 --- a/app/models/forum_thread.rb +++ b/app/models/forum_thread.rb @@ -5,7 +5,7 @@ class ForumThread < ApplicationRecord belongs_to :forum_category belongs_to :user - has_many :forum_posts + has_many :forum_posts, dependent: :destroy has_many :forum_subscriptions has_many :optin_subscribers, -> { where(forum_subscriptions: {subscription_type: :optin}) }, through: :forum_subscriptions, source: :user has_many :optout_subscribers, -> { where(forum_subscriptions: {subscription_type: :optout}) }, through: :forum_subscriptions, source: :user diff --git a/app/views/simple_discussion/forum_posts/_forum_post.html.erb b/app/views/simple_discussion/forum_posts/_forum_post.html.erb index 88e4809..79688d7 100644 --- a/app/views/simple_discussion/forum_posts/_forum_post.html.erb +++ b/app/views/simple_discussion/forum_posts/_forum_post.html.erb @@ -2,7 +2,6 @@ <%= content_tag :div, id: dom_id(forum_post), class: "forum-post" do %>