From f14a168bcef2fd815fec7c6c7ea0afcc6e8a62fc Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 19 Apr 2020 20:50:33 +0100 Subject: [PATCH] Implement deletion of announcements --- app/controllers/announcement_controller.rb | 7 +++++++ app/views/announcement/index.html.haml | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/announcement_controller.rb b/app/controllers/announcement_controller.rb index 4ab15b7a..f7219a4b 100644 --- a/app/controllers/announcement_controller.rb +++ b/app/controllers/announcement_controller.rb @@ -19,12 +19,19 @@ class AnnouncementController < ApplicationController end def edit + @announcement = Announcement.find(params[:id]) end def update end def destroy + if Announcement.destroy(params[:id]) + flash[:success] = "Announcement deleted successfully." + else + flash[:error] = "Failed to delete announcement." + end + redirect_to announcement_index_path end private diff --git a/app/views/announcement/index.html.haml b/app/views/announcement/index.html.haml index b7a759d4..a82a9066 100644 --- a/app/views/announcement/index.html.haml +++ b/app/views/announcement/index.html.haml @@ -5,4 +5,10 @@ = link_to "Add new", :announcement_new, class: "btn btn-default" - @announcements.each do |announcement| .panel.panel-default - = announcement.content + .panel-heading + = announcement.starts_at + .panel-body + = announcement.content + .panel-footer + = button_to "Edit", announcement_edit_path(id: announcement.id), class: 'btn btn-link' + = button_to "Delete", announcement_destroy_path(id: announcement.id), method: :delete, class: 'btn btn-link', confirm: 'Are you sure you want to delete this announcement?' \ No newline at end of file