From 6b5ed6ea7f7c488ec72f27d34819f6e23652bb1c Mon Sep 17 00:00:00 2001 From: jomo Date: Mon, 21 Apr 2014 01:53:32 +0200 Subject: [PATCH] add thread deleting --- app/controllers/forumthreads_controller.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb index d5c9412..060fd55 100644 --- a/app/controllers/forumthreads_controller.rb +++ b/app/controllers/forumthreads_controller.rb @@ -56,6 +56,19 @@ class ForumthreadsController < ApplicationController end + def destroy + if mod? || @thread.author.is?(current_user) + if @thread.destroy + flash[:notice] = "Thread deleted!" + else + flash[:alert] = "There was a problem while deleting this thread" + end + else + flash[:alert] = "You are not allowed to delete this thread" + end + redirect_to @thread.forum + end + private def check_permission