views:

135

answers:

3

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 tries 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.

+1  A: 

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.

mipadi
A: 

If you want to see what's behind #, try

raise probably_hash.class.to_s

Vojto
A: 

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.

jschulenklopper
the 'weather' element does exist, this is returned XML from the Google weather API. It's just strange because this exact same code works locally on my machine without an issue. I'll give length a shot though, thanks!
Brian Michel
After changing to .length and pushing to heroku, I now get a "block not given" error thrown. I'll just have to dig into this more, thanks again though!
Brian Michel
Which XML parser are you using to navigate the DOM? REXML, Nokogiri? It could be that the corresponding gem isn't installed in your Heroku application. You can supply a plain text `.gems` file to have Heroku install the gems that you need. See `http://docs.heroku.com/gems`.BTW, REXML's `children` returns an array, which has `length` or `size` method.
jschulenklopper