Implement deletion of announcements

This commit is contained in:
Karina Kwiatek 2020-04-19 20:50:33 +01:00
parent e3b89f7346
commit f14a168bce
2 changed files with 14 additions and 1 deletions

View File

@ -19,12 +19,19 @@ class AnnouncementController < ApplicationController
end end
def edit def edit
@announcement = Announcement.find(params[:id])
end end
def update def update
end end
def destroy 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 end
private private

View File

@ -5,4 +5,10 @@
= link_to "Add new", :announcement_new, class: "btn btn-default" = link_to "Add new", :announcement_new, class: "btn btn-default"
- @announcements.each do |announcement| - @announcements.each do |announcement|
.panel.panel-default .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?'