Events: add edit/update actions
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -22,4 +22,12 @@ class EventPolicy < ApplicationPolicy
|
||||
def show?
|
||||
owner_or_admin
|
||||
end
|
||||
|
||||
def edit?
|
||||
owner_or_admin
|
||||
end
|
||||
|
||||
def update?
|
||||
owner_or_admin
|
||||
end
|
||||
end
|
||||
|
||||
1
app/views/events/edit.html.slim
Normal file
1
app/views/events/edit.html.slim
Normal file
@@ -0,0 +1 @@
|
||||
= render "form", event: @event, submit_text: t("helpers.buttons.save"), method: :patch, url: event_path(@event)
|
||||
@@ -1,10 +1,12 @@
|
||||
.row
|
||||
.col
|
||||
h4.mb-3
|
||||
= t("events.index.manage_contests")
|
||||
h4.mb-3 style="margin-top: -1rem;"
|
||||
= t("events.show.manage_contests")
|
||||
a.ms-3.mt-3.btn.btn-primary.mb-4 href=edit_event_path(@event)
|
||||
= t("events.show.modify")
|
||||
.float-end
|
||||
a.btn.btn-primary.mb-4 href=new_contest_path(event: @event.id)
|
||||
= t("events.index.new_contest")
|
||||
a.mt-3.btn.btn-primary.mb-4 href=new_contest_path(event: @event.id)
|
||||
= t("events.show.new_contest")
|
||||
|
||||
.row.row-cols-1.row-cols-md-3.g-4
|
||||
- @contests.each do |contest|
|
||||
|
||||
Reference in New Issue
Block a user