added the ability to customize the path for new files when implementing an exercise

This commit is contained in:
Hauke Klement
2015-03-10 09:52:32 +01:00
parent 574c5c3a9c
commit ae1d654a62
3 changed files with 16 additions and 0 deletions

View File

@ -26,6 +26,17 @@ class ExercisesController < ApplicationController
end
end
def collect_paths(files)
unique_paths = files.map(&:path).reject(&:blank?).uniq
subpaths = unique_paths.map do |path|
(path.split('/').length + 1).times.map do |n|
path.split('/').shift(n).join('/')
end
end
subpaths.flatten.uniq
end
private :collect_paths
def create
@exercise = Exercise.new(exercise_params)
authorize!
@ -62,6 +73,7 @@ class ExercisesController < ApplicationController
def implement
@submission = Submission.where(exercise_id: @exercise.id, user_id: current_user.id).order('created_at DESC').first
@files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:name_with_extension)
@paths = collect_paths(@files)
end
def index