Show announcement validation errors on the frontend
This commit is contained in:
parent
2ecc746e23
commit
473f2cdcc5
|
@ -23,7 +23,9 @@ class AnnouncementController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
if Announcement.update(params[:id], announcement_params)
|
||||
@announcement = Announcement.find(params[:id])
|
||||
@announcement.update(announcement_params)
|
||||
if @announcement.save
|
||||
flash[:success] = "Announcement updated successfully."
|
||||
redirect_to announcement_index_path
|
||||
else
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
- provide(:title, generate_title("Edit announcement"))
|
||||
.container.j2-page
|
||||
= bootstrap_form_for(@announcement, url: {action: "update"}, method: "PATCH") do |f|
|
||||
- if @announcement.errors.any?
|
||||
.row
|
||||
.col-md-12
|
||||
.alert.alert-danger
|
||||
%strong
|
||||
= pluralize(@announcement.errors.count, "error")
|
||||
prohibited this announcement from being saved:
|
||||
%ul
|
||||
- @announcement.errors.full_messages.each do |err|
|
||||
%li= err
|
||||
.row
|
||||
.col-md-12
|
||||
= f.text_area :content, label: "Content"
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
- provide(:title, generate_title("Add new announcement"))
|
||||
.container.j2-page
|
||||
= bootstrap_form_for(@announcement, url: {action: "create"}) do |f|
|
||||
- if @announcement.errors.any?
|
||||
.row
|
||||
.col-md-12
|
||||
.alert.alert-danger
|
||||
%strong
|
||||
= pluralize(@announcement.errors.count, "error")
|
||||
prohibited this announcement from being saved:
|
||||
%ul
|
||||
- @announcement.errors.full_messages.each do |err|
|
||||
%li= err
|
||||
.row
|
||||
.col-md-12
|
||||
= f.text_area :content, label: "Content"
|
||||
|
|
Loading…
Reference in New Issue