Cant use cancan on rails 3 without mongoid #359

marcelloma opened this Issue May 3, 2011 · 2 comments


None yet

2 participants


Every rails command, rails server included seems to fail when cancan is installed.

The error is always:
/Library/Ruby/Gems/1.8/bundler/gems/cancan-ff13a82ddabd/lib/cancan/model_adapters/mongoid_adapter.rb:47: uninitialized constant Mongoid::Document (NameError)

ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]


gem 'rails', '3.0.5'
gem 'sqlite3'
gem 'jquery-rails'
gem 'rails3-jquery-autocomplete'
gem 'will_paginate', '~> 3.0.pre2'
gem 'data_table', '>= 0.1.9'
gem 'devise'
gem 'cancan'
gem 'paperclip'
gem 'rspec'
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'autotest-rails'
gem 'capybara'
gem 'cucumber'
gem 'cucumber-rails'
gem 'haml'
gem 'compass', '>= 0.10.6'


Hmm, it should only be loading the Mongoid adapter if Mongoid is available, which doesn't look like the case here unless one of the other gems is defining the Mongoid constant.

Try commenting out CanCan in your Gemfile, run bundle, start up rails console and then type Mongoid. Let me know what it says. It should give an error saying constant is undefined unless something is defining it.


I looked into it and it appears that the data_table gem is the problem. It's defining the Mongoid module which makes CanCan think Mongoid is loaded. For now try putting gem 'data_table under gem 'cancan' and see if that works. I'll update CanCan to actually check that Mongoid::Document is defined.

@ryanb ryanb closed this in cb9777b May 17, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment