Issues with Sinatra and Heroku
So I've created and published a Sinatra app to Heroku without any issues. I've even tested it locally with rackup to make sure it functions fine. There are a series of API calls to various places after a zip code is consumed from the URL, but Heroku just wants to tell me there is an server error.
I've added an error page that tr开发者_开发问答ies to give me more description, however, it tells me it can't perform a `count' for #, which I assume means hash. Here's the code that I think it's trying to execute...
if weather_doc.root.elements["weather"].children.count > 1
curr_temp = weather_doc.root.elements["weather/current_conditions/temp_f"].attributes["data"]
else
raise error(404, "Not A Valid Zip Code!")
end
If anyone wants to bang on it, it can be reached at, http://quiet-journey-14.heroku.com/ , but there's not much to be had.
Hash
doesn't have a count
method. It has a length
method. If #
really does refer to a hash object, then the problem is that you're calling a method that doesn't exist.
That #
doesn't refer to Hash, it's the first character of #<Array:0x2b2080a3e028>
. The part between the <
and >
is not shown in browsers (hiding the tags themselves), but visible with View Source.
Your real problem is not related to Ruby though, but to your navigation in the HTML or XML document (via DOM). Your statement
weather_doc.root.elements["weather"].children.count > 1
navigates the HTML/XML document, selecting the 'weather' elements, and (tries to) count the children. The result of the children
call does not have a method count
. Use length
instead.
BTW, are you sure that the document contains a tag <weather>
? Because that's what your're trying to select.
If you want to see what's behind #, try
raise probably_hash.class.to_s
精彩评论