如何从模型创建记录?

时间:2013-12-23 08:01:56

标签: ruby-on-rails-4

我有一个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

1 个答案:

答案 0 :(得分:0)

您忘记更新变量名称

 name= result.css('name').first.content
 gender = result.css('gender').first.content

 Result.create(name: name, gender: gender)