Add the ability to edit announcements

This commit is contained in:
Karina Kwiatek 2020-04-19 20:58:57 +01:00
parent f14a168bce
commit 6187cb0b6c
3 changed files with 26 additions and 3 deletions

View file

@ -23,6 +23,12 @@ class AnnouncementController < ApplicationController
end
def update
if Announcement.update(params[:id], announcement_params)
flash[:success] = "Announcement updated successfully."
redirect_to announcement_index_path
else
render 'announcement/edit'
end
end
def destroy

View file

@ -1,2 +1,19 @@
<h1>Announcement#edit</h1>
<p>Find me in app/views/announcement/edit.html.erb</p>
- provide(:title, generate_title("Edit announcement"))
.container.j2-page
= bootstrap_form_for(@announcement, url: {action: "update"}, method: "PATCH") do |f|
.row
.col-md-12
= f.text_area :content, label: "Content"
.row
.col-md-6
= f.url_field :link_href, label: "Link URL"
.col-md-6
= f.datetime_field :link_text, label: "Link text"
.row
.col-md-6
= f.datetime_field :starts_at, label: "Start time"
.col-md-6
= f.datetime_field :ends_at, label: "End time"
.row
.col-md-12.text-right
= f.submit class: "btn btn-primary"

View file

@ -10,5 +10,5 @@
.panel-body
= announcement.content
.panel-footer
= button_to "Edit", announcement_edit_path(id: announcement.id), class: 'btn btn-link'
= button_to "Edit", announcement_edit_path(id: announcement.id), method: :get, 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?'