我刚刚从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 ...
答案 0 :(得分:11)
以下对我有用:
添加到Gemfile:
gem "bson"
gem "moped", github: "mongoid/moped"
捆绑安装
添加到application.rb:
require "bson"
require "moped"
Moped::BSON = BSON
答案 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.
答案 2 :(得分:5)
在序列化cookie /会话中引用Moped::BSON
也可能导致此错误。删除cookie会修复它。