demarches-normaliennes/app/controllers/super_admins/release_notes_controller.rb
2023-11-08 18:22:11 +01:00

52 lines
1.3 KiB
Ruby

class SuperAdmins::ReleaseNotesController < ApplicationController
before_action :authenticate_super_admin!
before_action :set_note, only: [:edit, :update]
def index
@release_notes = ReleaseNote
.order(released_on: :desc, id: :asc)
.with_rich_text_body
end
def show
# allows refreshing a submitted page in error
redirect_to edit_super_admins_release_note_path(params[:id])
end
def new
@release_note = ReleaseNote.new(released_on: Date.current)
end
def create
@release_note = ReleaseNote.new(release_note_params)
if @release_note.save
redirect_to edit_super_admins_release_note_path(@release_note), notice: t('.success')
else
flash.now[:alert] = [t('.error'), @release_note.errors.full_messages].flatten
render :new
end
end
def edit
@release_note = ReleaseNote.find(params[:id])
end
def update
if @release_note.update(release_note_params)
redirect_to edit_super_admins_release_note_path(@release_note), notice: t('.success')
else
flash.now[:alert] = [t('.error'), @release_note.errors.full_messages].flatten
render :edit
end
end
private
def release_note_params
params.require(:release_note).permit(:released_on, :published, :body, categories: [])
end
def set_note
@release_note = ReleaseNote.find(params[:id])
end
end