From 81a079a25664565c3fc324ffa21cfeaae0dab0ae Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Thu, 8 Mar 2018 14:57:26 +0100 Subject: [PATCH] Allow to use simple templates in hints to embed captured error values --- app/models/structured_error.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/structured_error.rb b/app/models/structured_error.rb index c1f6669c..851b3fb8 100644 --- a/app/models/structured_error.rb +++ b/app/models/structured_error.rb @@ -3,11 +3,21 @@ class StructuredError < ActiveRecord::Base belongs_to :submission belongs_to :file, class_name: 'CodeOcean::File' + has_many :structured_error_attributes + def self.create_from_template(template, message_buffer, submission) instance = self.create(error_template: template, submission: submission) - template.error_template_attributes.each do |attribute| + template.error_template_attributes.each do | attribute | StructuredErrorAttribute.create_from_template(attribute, instance, message_buffer) end instance end + + def hint + content = error_template.hint + structured_error_attributes.each do | attribute | + content.sub! "{{#{attribute.error_template_attribute.key}}}", attribute.value if attribute.match + end + content + end end