Events: initial implementation
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
sto
2026-07-26 14:01:29 +02:00
parent fa8880abfc
commit 35b304d913
26 changed files with 389 additions and 24 deletions

View File

@@ -0,0 +1,56 @@
class EventsController < ApplicationController
before_action :set_event, only: %i[ destroy show ]
def index
authorize :event
@events = current_user.events.order(created_at: :desc)
@contests_without_event = current_user.contests.where(event: nil).size
@title = I18n.t("events.index.title", username: current_user.username)
end
def new
authorize :event
@event = Event.new
@title = I18n.t("events.new.title")
@nonav = true
end
def create
authorize :event
@event = Event.new(new_event_params)
@event.lang = @current_user.lang
@event.user_id = current_user.id
if @event.save
redirect_to "/events/#{@event.id}", notice: t("events.new.notice")
else
@title = I18n.t("events.new.title")
@nonav = true
render :new, status: :unprocessable_entity
end
end
def show
authorize @event
@contests = @event.contests
@title = @event.name
end
def destroy
authorize @event
@event.destroy
redirect_to events_path, notice: t("events.destroy.notice")
end
def set_event
@event = Event.find(params[:id])
end
def new_event_params
params.expect(event: [ :name, :shared_scoreboard ])
end
end