gpt4 book ai didi

ruby-on-rails - MongoID、Heroku、MongoLab/HQ,无插件

转载 作者:行者123 更新时间:2023-12-02 08:13:55 25 4
gpt4 key购买 nike

我目前想测试heroku mongoid mongolab/mongohq。

但是,我不想使用heroku插件,相反,我想配置mongoid以通过uri或其他设置直接使用mongolab/mongohq数据库。然而,这实际上效果并不好。

这是我到目前为止所做的事情:

rails new test-mongoid --skip-active-record

gem 文件

gem 'mongoid'
gem 'haml'
gem 'sass'

rails g mongoid:config

搭建测试模型

rails g scaffold Article title:string body:string

mongoid.yml

production:
host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>

其他尝试已经用 mongoid.yml 完成

production:
uri: mongodb://<user>:<password>@<host>:<port>/<database>

填写我的用户名密码等

使用 mongodb 在本地进行测试,一切正常。把它推送到heroku,不起作用。

有人已经这样做过以绕过那些heroku插件并知道如何处理它吗?

真诚的,舍弗勒

编辑

像这样配置我的 mongoid.yml

production:
sessions:
default:
hosts:
- <server>:<port>
username: <username>
password: <password>
database: <dbname>

似乎正在运行...但是如果我尝试转到脚手架文章索引app.herokuapp.com/articles

我明白了

[2012-08-18 21:54:30] INFO  WEBrick 1.3.1
[2012-08-18 21:54:30] INFO ruby 1.9.2 (2011-07-09) [x86_64-linux]
[2012-08-18 21:54:30] INFO WEBrick::HTTPServer#start: pid=2 port=57443
State changed from starting to up
=> Booting WEBrick
=> Rails 3.2.1 application starting in production on http:// 0.0. 0.0:57443
=> Ctrl-C to shutdown server
=> Call with -d to detach
Started GET "/articles" for 79.199.52.102 at 2012-08-18 21:54:31 +0000
Processing by ArticlesController#index as HTML
Completed 500 Internal Server Error in 264ms
ActionView::Template::Error (undefined method `[]' for nil:NilClass):
11:
10: </tr>

14: <td><%= article.title %></td>
15: <td><%= article.body %></td>
13: <tr>
Rendered articles/index.html.erb within layouts/application (208.2ms)
9: <th></th>
12: <% for article in @articles %>
app/controllers/articles_controller.rb:7:in `index'

app/views/articles/index.html.erb:12:in _app_views_articles_index_html_erb__1324099721200765517_18939540'

cache: [GET /articles] miss
GET safe-atoll-7856.herokuapp.com/articles dyno=web.1 queue=0 wait=0ms service=342ms status=500 bytes=643
Stopping remaining processes with SIGKILL
Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM
Process exited with status 137

最佳答案

添加

ruby '1.9.3'

到您的Gemfile。来自 Mongoid 3 + Heroku (MongoHQ) cause Moped::Errors::OperationFailure

如果您在本地使用 Ruby 1.9.3,您可能希望这能正常工作,但事实并非如此。

关于ruby-on-rails - MongoID、Heroku、MongoLab/HQ,无插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12018799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com