Im receiving this error in my Rails app and cant find the solution. I will add some code from the class where it fails. It might be a more of an architectural problem if you think so please do say and I will add more code from other classes. I basically only have this model, and one controller and another class which is located in lib. An then a view of course. Thanks in advance!
#app/models/news_api.rb
require 'open-uri'
class NewsApi
URL = "http://www.mysomething.com/partner/api/1_0/somerandomnumber/
channel/290/material/list/"
def self.download
new.document.css('news').map {|node| record(node) }
end
def document
Nokogiri::XML(open(URL))
puts URL.to_s
end
def record(node)
Story.new(node_to_hash(node))
end
def node_to_hash(node)
Hash[Story::ATTRIBUTES.collect {|attribute| [attribute, text(node, attribute)] }]
end
def text(node, selector)
node.css(selector).text
end
end
@idlefingers: Here is the code from my view. What Im doing is basically using Nokogiri to parse some xml from an API and then displaying the response in HTMl in my view.
<ul id="news">
<% @stories.each do |story| %>
<li class=" <%= story.type_of_media %>">
<h2><%= link_to story.header, story.url %></h2>
<p class="permalink"><%= link_to 'Trackback', story.url %></p>
<p class="meta">
<strong><%= story.source_name %></strong>
<br/>
<%= story.created_at %>
<br/>
<%= story.geo %>
</p>
<p class="summary"><%= story.summary %></p>
</li>
<% end %>
Where is the error coming from? At a glance, it looks like it’s coming from the
.documentmethod, but it isn’t clear. Can you add the error backtrace?The
.documentmethod as it stands will be returning the result ofputs URL.to_s, which will be nil. You just need to switch around the two lines in your.documentmethod by the looks of it…