extracted common controller behavior in order to reduce code duplication
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
module CodeOcean
|
||||
class FilesController < ApplicationController
|
||||
include CommonBehavior
|
||||
include FileParameters
|
||||
|
||||
def authorize!
|
||||
@ -10,25 +11,13 @@ module CodeOcean
|
||||
def create
|
||||
@file = CodeOcean::File.new(file_params)
|
||||
authorize!
|
||||
respond_to do |format|
|
||||
if @file.save
|
||||
format.html { redirect_to(implement_exercise_path(@file.context.exercise, tab: 2), notice: t('shared.object_created', model: File.model_name.human)) }
|
||||
format.json { render(:show, location: @file, status: :created) }
|
||||
else
|
||||
format.html { render(:new) }
|
||||
format.json { render(json: @file.errors, status: :unprocessable_entity) }
|
||||
end
|
||||
end
|
||||
create_and_respond(object: @file, path: implement_exercise_path(@file.context.exercise, tab: 2))
|
||||
end
|
||||
|
||||
def destroy
|
||||
@file = CodeOcean::File.find(params[:id])
|
||||
authorize!
|
||||
@file.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(@file.context, notice: t('shared.object_destroyed', model: File.model_name.human)) }
|
||||
format.json { head(:no_content) }
|
||||
end
|
||||
destroy_and_respond(object: @file, path: @file.context)
|
||||
end
|
||||
|
||||
def file_params
|
||||
|
Reference in New Issue
Block a user