【问题标题】:uninitialized constant Moped::BSON in rails 4 app on herokuHeroku上的rails 4应用程序中未初始化的常量Moped :: BSON
【发布时间】:2014-06-13 07:58:01
【问题描述】:

我刚刚从 rails 3 更新到 rails 4。一切都在本地工作,但部署在 heroku 上,我收到以下错误:

ActionView::Template::Error (uninitialized constant Moped::BSON):
3: %nav.navbar-collapse
4:   %ul.nav
5:     %li
6:       - if user_signed_in?
7:         = link_to 'Logout', destroy_user_session_path, :method=>'delete'
8:       - else
9:         = link_to 'Login', new_user_session_path
app/views/layouts/_navigation.html.haml:6:in `_app_views_layouts__navigation_html_haml___1118031947301940708_70104067139880'
app/views/layouts/application.html.haml:18:in `_app_views_layouts_application_html_haml__1093647294459268715_70104069850820'

当我访问 current_user 时,在其他 haml 文件中也会出现同样的错误 - 如果 current_user ...

【问题讨论】:

  • 我使用的是 devise 3.2.4 和 rails 4.1.0
  • 另外,使用 mongoid (4.0.0.beta1)

标签: heroku ruby-on-rails-4 mongoid


【解决方案1】:

以下内容对我有用:

添加到 Gemfile:

gem "bson"
gem "moped", github: "mongoid/moped"

捆绑安装

添加到 application.rb:

require "bson"
require "moped"
Moped::BSON = BSON

答案来自: https://github.com/mongoid/mongoid/issues/3455

【讨论】:

  • 为什么将 Moped::BSON 别名为 BSON ?为什么不直接解决核心问题并更改代码以引用 BSON 而不是 Moped::BSON?
【解决方案2】:

此错误也可能是由于在序列化的 cookie/会话中引用了 Moped::BSON。删除 cookie 会修复它。

【讨论】:

    【解决方案3】:

    从 Moped 2.0.0 开始查看 Moped 的作者的评论(在撰写本文时,该版本用作 mongoid 4.0.0 中的驱动程序):

    Moped's BSON implementation has been removed in favor of the 10gen bson gem 2.0 and higher. All Moped::BSON references should be changed to just BSON.
    

    https://github.com/mongoid/moped/blob/master/CHANGELOG.md

    【讨论】:

    • 是的,这个答案是对的。解决方案是使用“BSON::ObjectId”而不是“Moped::BSON::ObjectId”作为 Mongoid 的最新版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多