我有一个XML文件,我想从中创建一些记录。但我错过了一些东西,因为我的代码没有保存记录,但我没有收到任何错误。
MODEL
require 'open-uri'
class Result < ActiveRecord::Base
def self.raw_results
raw_xml = open("https://s3.amazonaws.com/...")
document = Nokogiri::XML(raw_xml)
articulos = document.css('ARTICULOS')
articulos.each do |result|
patient = result.css('nombre_paciente').first.content
gender = result.css('Sexo').first.content
Result.create!(patient: patient, gender: gender)
end
end
end
XML
https://gist.github.com/anonymous/8093365
答案 0 :(得分:0)
您忘记更新变量名称
name= result.css('name').first.content
gender = result.css('gender').first.content
Result.create(name: name, gender: gender)