extracted common controller behavior in order to reduce code duplication

This commit is contained in:
Hauke Klement
2015-02-05 12:28:09 +01:00
parent 74398b9939
commit a22a5af711
12 changed files with 96 additions and 186 deletions

View File

@ -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