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