Use file template to generate new file content
This commit is contained in:
@ -10,6 +10,9 @@ module CodeOcean
|
||||
|
||||
def create
|
||||
@file = CodeOcean::File.new(file_params)
|
||||
if @file.file_template_id
|
||||
@file.content = FileTemplate.find(@file.file_template_id).content
|
||||
end
|
||||
authorize!
|
||||
create_and_respond(object: @file, path: proc { implement_exercise_path(@file.context.exercise, tab: 2) })
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
module FileParameters
|
||||
def file_attributes
|
||||
%w(content context_id feedback_message file_id file_type_id hidden id name native_file path read_only role weight)
|
||||
%w(content context_id feedback_message file_id file_type_id hidden id name native_file path read_only role weight file_template_id)
|
||||
end
|
||||
private :file_attributes
|
||||
end
|
||||
|
@ -8,5 +8,8 @@
|
||||
.form-group
|
||||
= f.label(:file_type_id, t('activerecord.attributes.file.file_type_id'))
|
||||
= f.collection_select(:file_type_id, FileType.where(binary: false).order(:name), :id, :name, {selected: @exercise.execution_environment.file_type.try(:id)}, class: 'form-control')
|
||||
.form-group
|
||||
= f.label(:file_template_id, t('activerecord.attributes.file.file_template_id'))
|
||||
= f.collection_select(:file_template_id, FileTemplate.all.order(:name), :id, :name, {}, class: 'form-control')
|
||||
= f.hidden_field(:context_id)
|
||||
.actions = render('shared/submit_button', f: f, object: CodeOcean::File.new)
|
||||
|
Reference in New Issue
Block a user