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

Jef*_*sui 6 heroku mongoid ruby-on-rails-4

我刚刚从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'
Run Code Online (Sandbox Code Playgroud)

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

Jef*_*sui 11

以下对我有用:

添加到Gemfile:

gem "bson"
gem "moped", github: "mongoid/moped"
Run Code Online (Sandbox Code Playgroud)

捆绑安装

添加到application.rb:

require "bson"
require "moped"
Moped::BSON = BSON
Run Code Online (Sandbox Code Playgroud)

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


JAR*_*ans 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.
Run Code Online (Sandbox Code Playgroud)

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


Mac*_*ski 5

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