Sinatra 和 Heroku 的问题
因此,我创建了一个 Sinatra 应用程序并将其发布到 Heroku,没有任何问题。我什至用rackup 在本地对其进行了测试,以确保其功能正常。从 URL 中使用邮政编码后,会有一系列对各个地方的 API 调用,但 Heroku 只是想告诉我服务器出现错误。
我添加了一个错误页面,试图为我提供更多描述,但是,它告诉我它无法对 # 执行“计数”,我认为这意味着哈希。这是我认为它试图执行的代码...
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
如果有人想敲击它,可以访问 http://quiet-journey-14.heroku.com/ ,但没什么可做的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Hash
没有count
方法。它有一个length
方法。如果#
确实引用了哈希对象,那么问题就在于您正在调用一个不存在的方法。Hash
doesn't have acount
method. It has alength
method. If#
really does refer to a hash object, then the problem is that you're calling a method that doesn't exist.#
并不是指 Hash,它是#
的第一个字符。<
和>
之间的部分不会在浏览器中显示(隐藏标签本身),但通过查看源代码可见。不过,您真正的问题与 Ruby 无关,而是与 HTML 或 XML 文档(通过 DOM)中的导航有关。你的陈述
导航 HTML/XML 文档,选择“天气”元素,并(尝试)对子元素进行计数。
children
调用的结果没有方法count
。请改用length
。顺便说一句,您确定文档包含标签
吗?因为这就是你想要选择的。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
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 methodcount
. Uselength
instead.BTW, are you sure that the document contains a tag
<weather>
? Because that's what your're trying to select.如果您想查看 # 后面的内容,请尝试
raise likely_hash.class.to_s
If you want to see what's behind #, try
raise probably_hash.class.to_s