From 773088798c6f2568202b027a50b23a4212d946e8 Mon Sep 17 00:00:00 2001 From: "leo.selig" Date: Sat, 13 Feb 2016 11:54:30 +0100 Subject: [PATCH] Fix array to string cast error - accidental trailing comma caused this (apparently that's a thing in Ruby...) - cleaned up attribute assignments a little bit (persisted/validated/neither assignments) (leoselig/codeocean#1) --- app/controllers/exercises_controller.rb | 5 +++-- app/models/exercise.rb | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 25f522f3..07bd033d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -70,8 +70,9 @@ class ExercisesController < ApplicationController begin user = user_for_oauth2_request() exercise = Exercise.new - exercise.from_proforma_xml(request.body.read) - exercise.update(:user => user) + request_body = request.body.read + exercise.from_proforma_xml(request_body) + exercise.user = user saved = exercise.save if saved render :text => 'SUCCESS', :status => 200 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 9eabb874..1b917ecb 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -109,8 +109,11 @@ class Exercise < ActiveRecord::Base def from_proforma_xml(xml_string) # how to extract the proforma functionality into a different module in rails? xml = Nokogiri::XML(xml_string) - self.title = xml.xpath('/root/p:task/p:meta-data/p:title/text()')[0].content - self.description = xml.xpath('/root/p:task/p:description/text()')[0].content, + xml.collect_namespaces + self.attributes = { + title: xml.xpath('/root/p:task/p:meta-data/p:title/text()')[0].content, + description: xml.xpath('/root/p:task/p:description/text()')[0].content + } self.execution_environment_id = 1 end