我目前正試圖從一個xml文件中讀取,該文件記錄了PBS上的作業。我已經succesfullly成功地解析代碼,但我無法在objtects插入到我的數據庫,我收到此錯誤:Ruby libxml解析並插入到數據庫
「你有一個零對象時,你沒想到吧 你可能會認爲一個實例。
require 'xml/libxml'
class Job < ActiveRecord::Base
JOB_DIR = File.join('data', 'jobs')
attr_reader :jobid, :user, :group, :jobname, :queue, :ctime
attr_reader :qtime, :etime, :start, :owner
def initialize(jobid, user, group, jobname, queue, ctime, qtime, etime, start, owner)
@jobid, @user, @group, @jobname, @queue = jobid, user, group, jobname, queue
@ctime, @qtime, @etime, @start, @owner = ctime, qtime, etime, start, owner
end
def self.find_all()
jobs = []
input_file = "#{JOB_DIR}/1.xml"
doc = XML::Document.file(input_file)
doc.find('//execution_record').each do |node|
jobs << Job.new(
node.find('jobid').to_a.first.content,
node.find('user').to_a.first.content,
node.find('group').to_a.first.content,
node.find('jobname').to_a.first.content,
node.find('queue').to_a.first.content,
node.find('ctime').to_a.first.content,
node.find('qtime').to_a.first.content,
node.find('etime').to_a.first.content,
node.find('start').to_a.first.content,
node.find('owner').to_a.first.content
)
end
jobs
end
end
的我型控制器:
class JobController < ApplicationController
def index
@jobs = Job.find_all()
end
def create
@jobs = Job.find_all()
for job in @jobs
job.save
end
end
end
的的ActiveRecord :: Base的同時評估nil.delete」
這是我的模型時發生錯誤10
我將不勝感激任何幫助......謝謝!
謝謝Mikej,這非常有幫助! – jalagrange 2010-07-20 14:02:04
@jalagrange我知道你已經接受了答案,但我不覺得我已經幫了你很多 - 隨時發佈任何後續問題,當你進一步瞭解。 – mikej 2010-07-20 14:15:27