Add simple controller to create events
This commit is contained in:
28
app/controllers/events_controller.rb
Normal file
28
app/controllers/events_controller.rb
Normal 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
|
7
app/policies/event_policy.rb
Normal file
7
app/policies/event_policy.rb
Normal file
@ -0,0 +1,7 @@
|
||||
class EventPolicy < AdminOnlyPolicy
|
||||
|
||||
def create?
|
||||
everyone
|
||||
end
|
||||
|
||||
end
|
@ -168,6 +168,8 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
resources :events, only: [:create]
|
||||
|
||||
post "/evaluate", to: 'remote_evaluation#evaluate', via: [:post]
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user