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)
This commit is contained in:
leo.selig
2016-02-13 11:54:30 +01:00
parent f787445e5b
commit 773088798c
2 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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