Add simple controller to create events

This commit is contained in:
Maximilian Grundke
2018-08-14 18:08:25 +02:00
parent f1278a7f48
commit 7d7234ce63
3 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,28 @@
class EventsController < ApplicationController
def authorize!
authorize(@event || @events)
end
private :authorize!
def create
@event = Event.new(event_params)
authorize!
respond_to do |format|
if @event.save
format.html { head :created }
format.json { head :created }
else
format.html { head :unprocessable_entity }
format.json { head :unprocessable_entity }
end
end
end
def event_params
params[:event].permit(:category, :data, :exercise_id, :file_id)
.merge(user_id: current_user&.id, user_type: current_user&.class.name)
end
private :event_params
end

View File

@ -0,0 +1,7 @@
class EventPolicy < AdminOnlyPolicy
def create?
everyone
end
end

View File

@ -168,6 +168,8 @@ Rails.application.routes.draw do
end
end
resources :events, only: [:create]
post "/evaluate", to: 'remote_evaluation#evaluate', via: [:post]
end