Mongoid在Ruby 1.9.3上失败 [英] Mongoid fails on ruby 1.9.3

查看:109
本文介绍了Mongoid在Ruby 1.9.3上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在玩mongo的东西。创建了一个新的heroku应用程序,添加了一个mongolab选项,但每个mongoid方法都失败了。



我搜索了一下,看起来这个问题在ruby之前很常见1.9.3,但我正在运行1.9.3。



以下是最简单的失败示例:

<$ p $
需要'sinatra'
要求'mongoid'
要求'json'
如果开发需要sinatra / reloader?

Mongoid.load!(mongoid.yml)

class公司
包含Mongoid :: Document

字段:代码,类型:字符串
字段:扇区,类型:字符串
字段:share_id,类型:整数
字段:jse_code,类型:整数
结束

get '/'做
你好
结束

得到'/ company'做
Company.exists?
结束

我在本地运行这个(对着mongolab db)或者在heroku上,我得到同样的错误:

  12:22:33 web.1 | NoMethodError  - 未定义的方法匹配零:NilClass:
12:22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions/mongo_uri.rb:49:in`initialize'
12:22: 33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:103:in`new'
12:22: 33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:103:in`parse'
12:22: 33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:62:in`create_session'
12:22: 33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:43:in`default'
12:22: 33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:109:in`default'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:378:in`__session__'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:213:in`mongo_session'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:157:in`collection'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual/mongo.rb:216:in`initialize'
12:22: 33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual.rb:47:in`new'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual.rb:47:in`create_context'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual.rb:30:in`context'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual.rb:20:in`rescue in exists?'
12:22 :33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual.rb:18:in`exists?'
12:22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/finders.rb:43:in`exists?'
12:22:33 web.1 | app.rb:22:在< main>的块中
12:22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in`block in compile!'
12:22 :33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in`[]'
12:22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in`block(3 levels)in route!'
12:22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:851:in`route_eval'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in`block(2 levels)in route!'
12:22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:872:in`block in process_route'
12:22: 33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in`catch'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in' process_route'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:834:in`block in route!'
12:22 :33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in`each'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in`route!'
12:22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:936:in`dispatch!'
12:22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in`block in call!'
12:22 :33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in`block in invoke'
12:22: 33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in`catch'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in`invoke'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in`call!'
12:22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:755:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in`call'
12: 22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in`call'
12: 22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in`call'
12: 22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in`call'
12: 22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in`call'
12: 22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/logger.rb:15:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:136:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:129:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/head.rb:9:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/showexceptions.rb:21:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:99:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in`block in call'
12:22: 33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:1471:in`synchronize'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in`call'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/thin-1.5.0/lib/thin/connection.rb:81:in`block in pre_process'
12:22: 33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/thin-1.5.0/lib/thin/connection.rb:79:in`catch'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/thin-1.5.0/lib/thin/connection.rb:79:in`pre_process'
12:22:33 web .1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/eventmachine-1.0.0/lib/eventmachine.rb:1037:in`call'
12:22:33 web.1 | /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/eventmachine-1.0.0/lib/eventmachine.rb:1037:in`spawn_threadpool'block
12:22:33 web .1 | 127.0.0.1 - - [21 / Nov / 2012 12:22:33]GET /__sinatra__/500.png HTTP / 1.1200 31056 0.0062

我做错了什么?



已更新这里是我的mongoid.yml:

 制作:
会话:
默认值:
uri:<%= ENV ['MONGOLAB_URI'] %GT;
选项:
skip_version_check:true
safe:true
开发:
会话:
默认值:
uri:<%= ENV [ 'MONGOLAB_URI']%>


解决方案

基于堆栈跟踪,它看起来像 mongo_uri 正在传递空值。我会在 mongoid.yml




  • 中检查以下内容:正确的位置/参数 load!指向正确的位置 >如果它引用了它们在您的环境中设置的任何环境变量(例如, MongoLab Heroku附加组件的MONGOLAB_URI

  • ul>

    来自 mongo_uri的相关行.rb:49 ,其中引发异常:

     #从提供的字符串中创建新的uri。 

    #@example创建新的uri。
    #MongoUri.new(uri)

    #@param [字符串]字符串uri字符串。

    #@since 3.0.0
    def initialize(string)
    @match = string.match(URI)
    end


    So I'm playing around with mongo stuffs. Created a new heroku app, added a mongolab option to it, but every mongoid method fails.

    I googled around, and it looks like this issue was common with ruby prior to 1.9.3, but I'm running 1.9.3.

    Here's the simplest failing sample:

    require 'sinatra'
    require 'mongoid'
    require 'json'
    require "sinatra/reloader" if development?
    
    Mongoid.load!("mongoid.yml")
    
    class Company
        include Mongoid::Document
    
        field :code, type: String
        field :sector, type: String
        field :share_id, type: Integer
        field :jse_code, type: Integer
    end
    
    get '/' do
        "Hello" 
    end
    
    get '/company' do
        Company.exists?
    end
    

    Wether I run this locally (against the mongolab db) or on heroku, I get the same kind of error:

    12:22:33 web.1  | NoMethodError - undefined method `match' for nil:NilClass:
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions/mongo_uri.rb:49:in `initialize'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:103:in `new'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:103:in `parse'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:62:in `create_session'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:43:in `default'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:109:in `default'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:378:in `__session__'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:213:in `mongo_session'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:157:in `collection'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual/mongo.rb:216:in `initialize'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual.rb:47:in `new'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual.rb:47:in `create_context'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual.rb:30:in `context'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual.rb:20:in `rescue in exists?'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/contextual.rb:18:in `exists?'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.13/lib/mongoid/finders.rb:43:in `exists?'
    12:22:33 web.1  |   app.rb:22:in `block in <main>'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in `block in compile!'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `[]'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `block (3 levels) in route!'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:851:in `route_eval'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `block (2 levels) in route!'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:872:in `block in process_route'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in `catch'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in `process_route'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:834:in `block in route!'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in `each'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in `route!'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:936:in `dispatch!'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in `block in call!'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `block in invoke'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `catch'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `invoke'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in `call!'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:755:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/logger.rb:15:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:136:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:129:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/showexceptions.rb:21:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:99:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in `block in call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:1471:in `synchronize'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/thin-1.5.0/lib/thin/connection.rb:81:in `block in pre_process'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/thin-1.5.0/lib/thin/connection.rb:79:in `catch'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/thin-1.5.0/lib/thin/connection.rb:79:in `pre_process'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/eventmachine-1.0.0/lib/eventmachine.rb:1037:in `call'
    12:22:33 web.1  |   /Users/sdx/.rvm/gems/ruby-1.9.3-p327/gems/eventmachine-1.0.0/lib/eventmachine.rb:1037:in `block in spawn_threadpool'
    12:22:33 web.1  | 127.0.0.1 - - [21/Nov/2012 12:22:33] "GET /__sinatra__/500.png HTTP/1.1" 200 31056 0.0062
    

    What am I doing wrong ?

    UPDATED here's my mongoid.yml:

    production:
        sessions:
            default:
                uri: <%= ENV['MONGOLAB_URI'] %>
                options:
                    skip_version_check: true
                    safe: true
    development:
        sessions:
            default:
                uri: <%= ENV['MONGOLAB_URI'] %>
    

    解决方案

    Based on the stack trace it looks like the constructor for mongo_uri is being passed a null value. I'd check the following in your mongoid.yml:

    • it's in the right place / the argument to load! points to the right place
    • it's configured correctly
    • if it refers to any environment variables (e.g. MONGOLAB_URI for the MongoLab Heroku add-on) that they're set in your environment

    The relevant lines from mongo_uri.rb:49, where the exception is being thrown:

      # Create the new uri from the provided string.
      #
      # @example Create the new uri.
      #   MongoUri.new(uri)
      #
      # @param [ String ] string The uri string.
      #
      # @since 3.0.0
      def initialize(string)
        @match = string.match(URI)
      end
    

    这篇关于Mongoid在Ruby 1.9.3上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆