Heroku、Mongoid 和 MongoHQ 的应用程序崩溃
我正在尝试让我的应用程序在线并与 Heroku 一起运行。
该应用程序使用 MongoHQ 和 Mongoid。
我读过多个指南,只是说要添加此内容,“uri: <%= ENV['MONGOHQ_URL'] %>”到 mongoid.yml 文件,但它对我不起作用。
这是我从 Heroku 收到的错误,
“应用程序错误
应用程序中发生错误,无法提供您的页面。请稍后重试。
如果您是应用程序所有者,请检查日志以了解详细信息。”
这就是我的 $ heroku 日志
2011-03-12T21:09:57-08:00 heroku[router]: Error H10 (App crashed) ->; GET autommator.heroku.com/ dyno=none 队列=0 等待=0ms 服务=0ms 字节=0 2011-03-12T21:09:57-08:00heroku[nginx]:GET / HTTP/1.1 | 76.112.220.158 | 795 | 795 http | 503
这是我的 mongoid.yml 文件。
require 'yaml'
YAML::ENGINE.yamler= 'syck'
defaults: &defaults
host: localhost
# slaves:
# - host: slave1.local
# port: 27018
# - host: slave2.local
# port: 27019
development:
<<: *defaults
host: localhost
database: autommator_development
test:
<<: *defaults
host: localhost
database: autommator_test
# set these environment variables on your prod server
production:
uri: <%= ENV['MONGOHQ_URL'] %>
host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
完全没有想法。
谢谢。
I am trying to get my application online and functioning with Heroku.
The application uses MongoHQ and Mongoid.
I have read multiple guides that just say to add this, "uri: <%= ENV['MONGOHQ_URL'] %>" to the mongoid.yml file, but it's not working for me.
This is the error I get from Heroku,
"Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details."
This is what it's in my $ heroku logs
2011-03-12T21:09:57-08:00 heroku[router]: Error H10 (App crashed) -> GET autommator.heroku.com/ dyno=none queue=0 wait=0ms service=0ms bytes=0
2011-03-12T21:09:57-08:00heroku[nginx]: GET / HTTP/1.1 | 76.112.220.158 | 795 | http | 503
Here is my mongoid.yml file.
require 'yaml'
YAML::ENGINE.yamler= 'syck'
defaults: &defaults
host: localhost
# slaves:
# - host: slave1.local
# port: 27018
# - host: slave2.local
# port: 27019
development:
<<: *defaults
host: localhost
database: autommator_development
test:
<<: *defaults
host: localhost
database: autommator_test
# set these environment variables on your prod server
production:
uri: <%= ENV['MONGOHQ_URL'] %>
host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
Completely out of ideas.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要将 mongoid 与 Heroku 附加组件一起使用,您的 mongoid.yml 应如下所示:
您不应该在那里有任何其他数据库连接信息,因此请提取主机、端口、用户名、密码和数据库字段。
To use mongoid with the Heroku add-on, your mongoid.yml should look like this:
You shouldn't have any other database connection information there, so pull out the host, port, username, password and database fields.
今天早上我发现了这个问题。我的开发 PC 上的应用程序运行的是 Ruby 1.9.2。 Heroku 默认为 1.8.7。
我刚刚运行了本文中的命令 http://devcenter.heroku.com/articles/bamboo 重新加载,一切正常。
谢谢你们的帮助。
I figured out the problem this morning. My app on my development PC is running Ruby 1.9.2. Heroku defaults to 1.8.7.
I just ran the commands found in this article, http://devcenter.heroku.com/articles/bamboo reloaded, and everything works.
Thanks for the help guys.
您是通过 Heroku 插件还是直接从 MongoHQ 创建数据库?如果您直接从 MongoHQ 执行此操作,则需要手动设置变量。
如果它是通过 heroku 插件那么它应该为您创建。如果添加变量没有帮助,请向我们发送支持票证[电子邮件受保护] 我们可以进一步挖掘。
Did you create the database through the Heroku addon or directly from MongoHQ? If you did it directly from MongoHQ then you will need to set the variables manually.
If it was via the heroku addon then it should be created for you. If adding the variable doesn't help send us a support ticket to [email protected] and we can dig further.
也许我在这里说的是显而易见的事情,但这样做是从环境中提取这些人的价值观。为了使其工作,您需要在 heroku 环境中设置变量(MONGOHQ_URL 等)。我认为该命令类似于
heroku config:add MONGOHQ_URL=XXXXX
或类似的命令。一定要在 heroku 文档中查找它。不过,考虑到您要从环境中获取价值,YML 似乎是错误的选择。我建议使用初始化文件来设置这些值,或者将它们放入某种 MONGO_CONFIG 中,您可以在任何地方读取它们。如果您走这条路,您还可以将它们设置为环境变量(如果预设),或者回退到 YML 文件(如果没有)。
这个railscast展示了我所说的http://railscasts.com/episodes/ 85-yaml-configuration-file 不同之处在于,当需要设置变量时,您将其设置为
ENV['XXX'] if ENV['XXX']
Maybe I'm stating the obvious here, but what that's doing is pulling the values of those from the environment. In order for that to work, you would need to have set the variables (MONGOHQ_URL, etc) in the heroku environment. I think the command for that is something like
heroku config:add MONGOHQ_URL=XXXXX
or something like that. Definitely look it up in the heroku docs.Given that you're getting the values out of the environment, though, the YML seems the wrong way to go. I suggest and initializer file that just sets these value, or puts them into some sort of MONGO_CONFIG where you can read them anywhere. If you go this route, you could also set them to the env variables if preset, or fall back to the YML file if not.
This railscast shows kind of what I'm talking about http://railscasts.com/episodes/85-yaml-configuration-file The difference is that when it comes time to set the variable, you set it to
ENV['XXX'] if ENV['XXX']