【问题标题】:MongoID, Heroku, MongoLab/HQ, w/o addonsMongoID、Heroku、MongoLab/HQ,无插件
【发布时间】:2012-08-14 16:04:43
【问题描述】:

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

但是,我不想使用 heroku 插件,相反,我想配置 mongoid 以通过 uri oder 其他设置直接使用 mongolab/mongohq 数据库。但是,这并没有真正奏效。

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

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

宝石文件

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

【问题讨论】:

  • 您遇到了什么错误? Heroku 的 MongoHQ 插件就像所有其他 MongoHQ 数据库一样,它只是在添加时创建一个 MONGOHQ_URL Heroku 配置。
  • 您使用的是 Mongoid 3.x 吗?如果是这样,您正在运行哪个版本的 Ruby,以及您在哪个 Heroku 堆栈上运行。你能告诉我们你在堆栈中看到了什么错误吗?杰森·蒙戈总部

标签: ruby-on-rails ruby-on-rails-3


【解决方案1】:

在你的mongoid.yml:

production:
  host: your_host.mongohq.com
  port: 10078
  username:your_user_name
  password: your_pass
  database: your_db_name

所以实际上,你所做的很好,应该只是无效或格式不正确的值

【讨论】:

    【解决方案2】:

    添加

    ruby '1.9.3'
    

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

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

    【讨论】:

    • 很棒的@Leopd,我已经为此苦苦挣扎了一个多小时......谢谢:)
    猜你喜欢
    • 2016-03-06
    • 2011-12-03
    • 2012-02-10
    • 2012-12-07
    • 2016-05-11
    • 2015-05-07
    • 2014-01-18
    • 2013-08-07
    • 2012-02-22
    相关资源
    最近更新 更多