Sinatra 和 Heroku 的问题

发布于 2024-09-02 21:06:50 字数 598 浏览 1 评论 0原文

因此,我创建了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

惜醉颜 2024-09-09 21:06:50

Hash 没有 count 方法。它有一个 length 方法。如果 # 确实引用了哈希对象,那么问题就在于您正在调用一个不存在的方法。

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.

厌倦 2024-09-09 21:06:50

# 并不是指 Hash,它是 # 的第一个字符。 <> 之间的部分不会在浏览器中显示(隐藏标签本身),但通过查看源代码可见。

不过,您真正的问题与 Ruby 无关,而是与 HTML 或 XML 文档(通过 DOM)中的导航有关。你的陈述

weather_doc.root.elements["weather"].children.count > > 1

导航 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

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.

谷夏 2024-09-09 21:06:50

如果您想查看 # 后面的内容,请尝试

raise likely_hash.class.to_s

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

raise probably_hash.class.to_s

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文