Events: add edit/update actions
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run

This commit is contained in:
sto
2026-07-28 13:45:27 +02:00
parent 17d99a92c0
commit b8a2e4b0b4
6 changed files with 49 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
class EventsController < ApplicationController
before_action :set_event, only: %i[ destroy show ]
before_action :set_event, only: %i[ destroy show edit update ]
def index
authorize :event
@@ -20,7 +20,7 @@ class EventsController < ApplicationController
def create
authorize :event
@event = Event.new(new_event_params)
@event = Event.new(event_params)
@event.lang = @current_user.lang
@event.user_id = current_user.id
if @event.save
@@ -39,6 +39,25 @@ class EventsController < ApplicationController
@title = @event.name
end
def edit
authorize @event
@title = I18n.t("events.edit.title")
@nonav = true
end
def update
authorize @event
if @event.update(event_params)
redirect_to event_path(@event), notice: t("events.edit.notice")
else
@title = I18n.t("events.edit.title")
@nonav = true
render :edit, status: :unprocessable_entity
end
end
def destroy
authorize @event
@@ -50,7 +69,7 @@ class EventsController < ApplicationController
@event = Event.find(params[:id])
end
def new_event_params
def event_params
params.expect(event: [ :name, :shared_scoreboard ])
end
end