0

我在 heroku 上有一个使用 mongoid 和 delay_job 的应用程序,我已将 ruby​​ 版本从 1.9.2 更改为 1.9.3 我收到错误

undefined method `match' for nil:NilClass

当我尝试将对象保存到 mongoid 数据库时,我的 mongoid.yaml 文件看起来像

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

痕迹在这里

NoMethodError: undefined method `match' for nil:NilClass
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/mongo_uri.rb:49:in `initialize'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:103:in `new'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:103:in `parse'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:62:in `create_session'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:43:in `default'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:109:in `default'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:378:in `__session__'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:213:in `mongo_session'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:157:in `collection'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions.rb:25:in `collection'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/operations.rb:27:in `collection'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/operations/insert.rb:27:in `block in persist'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/insertion.rb:25:in `block (2 levels) in prepare'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:403:in `_run__4034630009416245289__create__685777988298500290__callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in `__run_callback'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_create_callbacks'

... 2 levels...
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/insertion.rb:24:in `block in prepare'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:403:in `_run__4034630009416245289__save__685777988298500290__callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in `__run_callback'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/callbacks.rb:114:in `run_callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/insertion.rb:23:in `prepare'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence/operations/insert.rb:26:in `persist'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence.rb:50:in `insert'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.13/lib/mongoid/persistence.rb:79:in `save'
from (irb):2
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'

任何人都可以帮助我吗?提前致谢

4

1 回答 1

1

发生错误是因为此方法https://github.com/mongoid/mongoid/blob/v3.0.13/lib/mongoid/sessions/mongo_uri.rb#L49的输入参数为零。

进一步备份调用堆栈以找出该字符串的来源(请参阅https://github.com/mongoid/mongoid/blob/v3.0.13/lib/mongoid/sessions/factory.rb#L103)它看起来像您的uri配置参数为零。uri 键存在但为空,因此您可以MONGOHQ_URL通过运行来检查配置参数heroku config。这应该由 MongoHQ 插件设置。

堆栈跟踪中的 Ruby 1.9.1 路径无需担心。请参阅为什么 Heroku 堆栈跟踪表明 Ruby 1.9.1 正在使用中?

于 2013-06-28T08:11:04.920 回答