Fix exercise update
This commit is contained in:
@ -6,12 +6,14 @@ module CodeOcean
|
|||||||
class FileNameValidator < ActiveModel::Validator
|
class FileNameValidator < ActiveModel::Validator
|
||||||
def validate(record)
|
def validate(record)
|
||||||
existing_files = File.where(name: record.name, path: record.path, file_type_id: record.file_type_id,
|
existing_files = File.where(name: record.name, path: record.path, file_type_id: record.file_type_id,
|
||||||
context_id: record.context_id, context: record.context).to_a
|
context_id: record.context_id, context_type: record.context_type).to_a
|
||||||
unless existing_files.empty?
|
unless existing_files.empty?
|
||||||
|
if (not record.context.is_a?(Exercise)) || (record.context.new_record?)
|
||||||
record.errors[:base] << 'Duplicate'
|
record.errors[:base] << 'Duplicate'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class File < ActiveRecord::Base
|
class File < ActiveRecord::Base
|
||||||
include DefaultValues
|
include DefaultValues
|
||||||
|
Reference in New Issue
Block a user