Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This appears to be issue with what Nokogiri expects as parameters to the parse method that is being called. The first issue I see, is that you are passing in the encoding option in the wrong parameter slot,</p> <p>A <a href="http://nokogiri.org/tutorials/parsing_an_html_xml_document.html" rel="nofollow">parsing example</a> from Nokogiri project page that specifies encoding</p> <pre><code>Nokogiri.XML('&lt;foo&gt;&lt;bar /&gt;&lt;foo&gt;', nil, 'EUC-JP') </code></pre> <p>Notice the encoding is the third parameter, not the second. But that still does not fully explain the behavior you are seeing, as the encoding should simply be ignored.</p> <p>Per the Nokogiri documentation a call to Nokogiri::HTML() is a convenience method for the parse method.</p> <p>Code for Nokogiri::HTML::parse</p> <pre><code> def parse thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT_HTML, &amp;block document.parse(thing, url, encoding, options, &amp;block) end </code></pre> <p>The <a href="http://nokogiri.org/Nokogiri/HTML/Document.html" rel="nofollow">source</a> for the Nokogiri::HTML::Document parse method is a bit long, but here is the relevant part though:</p> <pre><code> string_or_io.respond_to?(:encoding) unless string_or_io.encoding.name == "ASCII-8BIT" encoding ||= string_or_io.encoding.name end end </code></pre> <p>Notice <strong>string_or_io.encoding.name</strong>, this matches the error your saw, <strong>undefined method 'name' for "UTF-8":String (NoMethodError)</strong>. </p> <p>Does your search_results object has an attribute with a key value pair of {:encoding => 'UTF-8'}? It appears Nokogiri is looking for the encoding to store an object that then has a name attribute of 'UTF-8'.</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