在heroku上的rails 4 app中未初始化的常量Moped :: BSON

时间:2014-04-27 22:24:20

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

我刚刚从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   ...

3 个答案:

答案 0 :(得分:11)

以下对我有用:

添加到Gemfile:

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

捆绑安装

添加到application.rb:

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

回答: https://github.com/mongoid/mongoid/issues/3455

答案 1 :(得分:6)

从Moped的作者看Moped 2.0.0的评论(截至本文撰写时,该版本用作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

答案 2 :(得分:5)

在序列化cookie /会话中引用Moped::BSON也可能导致此错误。删除cookie会修复它。