Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure on the causes of the error message you're seeing because I can't see anywhere that you're trying to invoke a <code>delete</code> method, however this does seem like a slightly confused use of ActiveRecord.</p> <p>If you have a <code>jobs</code> database table with fields <code>jobid</code>, <code>user</code>, <code>group</code>, <code>jobname</code> etc. then ActiveRecord will create accessor methods for these and you should not be using <code>attr_reader</code> or overriding <code>initialize</code>. You should also not be setting values value instance variables (<code>@jobid</code> etc.) If you <em>don't</em> have such fields on your table then there is nothing in your current code to map the values from the XML the database fields.</p> <p>Your <code>def self.find_all</code> method should probably be along the lines of:</p> <pre><code>def self.build_from_xml jobs = [] input_file = "#{JOB_DIR}/1.xml" doc = XML::Document.file(input_file) doc.find('//execution_record').each do |node| jobs &lt;&lt; Job.new( :jobid =&gt; node.find('jobid').to_a.first.content, :user =&gt; node.find('user').to_a.first.content, ... </code></pre> <p>Rails used to have a method of its own <code>find_all</code> to retrieve all existing records from the database so your method name is probably a bit misleading. Rails tends to use the <em>build</em> verb to mean <em>create a new model object but don't save it yet</em> so that's why I've gone with a name like <code>build_from_xml</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload