v1.1.rc1 crashes using Mongoid
Error when trying to start rails server etc...
/Users/druiden/.rvm/gems/ruby-1.8.7-p249/gems/devise-1.1.rc1/lib/devise/models.rb:6:in `included': undefined method `class_attribute' for Mongoid::Document::ClassMethods:Module (NoMethodError)
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/gems/devise-1.1.rc1/lib/devise/models.rb:5:in `class_eval'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/gems/devise-1.1.rc1/lib/devise/models.rb:5:in `included'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/gems/devise-1.1.rc1/lib/devise/orm/mongoid.rb:38:in `include'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/gems/devise-1.1.rc1/lib/devise/orm/mongoid.rb:38
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/gems/devise-1.1.rc1/lib/devise/orm/mongoid.rb:37:in `class_eval'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/gems/devise-1.1.rc1/lib/devise/orm/mongoid.rb:37
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:209:in `require'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:209:in `require'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:197:in `load_dependency'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:209:in `require'
from /Users/druiden/development/rails/streamio/config/initializers/devise.rb:87
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/gems/devise-1.1.rc1/lib/devise.rb:154:in `setup'
from /Users/druiden/development/rails/streamio/config/initializers/devise.rb:3
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:205:in `load'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:205:in `load'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:197:in `load_dependency'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:205:in `load'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/engine.rb:198
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/engine.rb:197:in `each'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/engine.rb:197
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:25:in `instance_exec'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:25:in `run'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:55:in `run_initializers'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:54:in `each'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/application.rb:109:in `initialize!'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/application.rb:81:in `send'
from /Users/druiden/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/application.rb:81:in `method_missing'
I'm using edge Mongoid from the master branch.
I'll fix it in next release. For this while, just require "active_support/core_ext/object/class_attribute" before requiring the orm file.
Actually, I think the above won't work! :(
yes, it doesn't. :-( More information below: http://groups.google.com/group/plataformatec-devise/browse_thread/thread/c4dda194455be107?pli=1
To make short, class_attribute is not available within Module objects, it's only for classes.. And Mongoid::Document is a module not a class as ActiveRecord::Base is.
Yes, exactly!
It appears to be broken on DataMapper as well (for the exact same reason).
I made a quick patch for my project and my tests are okay. Actually, I patched the hook method in models.rb. I just check if the base is a module or not, then I declare a method to access device_modules.
def hook(base)
if base.is_a?(Module)
base.class_eval do
attr_accessor :devise_modules
def devise_modules
@devise_modules ||= []
end
end
else
base.class_eval do
class_attribute :devise_modules, :instance_writer => false
self.devise_modules ||= []
end
end
end
I don't know if I miss something in the logic of the hook method but since it works for me.... José, let me know if you want me to fork the project, patch it and write some tests. I'll be pleased to help you.
Fix compatibility with Mongoid and Datamapper, closed by 9291ab55b895724d4608f7e3e2d771a8f92d87eb.
Thanks José !
I still get this error using devise 1.1.rc1 and Mongoid 2.0.0.beta4
This is my first time using Rails 3 and Mongoid so I am not sure what to check.
Just use Devise from git repository. :)
I still get this error with devise 1.1.rc1, checking out from git repository, and mongoid 2.0.0.beta6
Update:
I got rid of this error using both master branch of rails and devise
boblu: Im having the same problem, how did you go about in the Gemfile? Like this? gem 'rails', :git => 'http://github.com/rails/rails.git', :branch => 'master' gem 'devise', :git => 'http://github.com/plataformatec/devise.git', :branch => 'master'
I went with gem 'rails', :git => 'http://github.com/rails/rails.git' gem 'devise', :git => 'http://github.com/plataformatec/devise.git'
Had the same error tonight with rails-3.0.0.beta3 and devise-1.1.rc1. Grabbing both from git as boblu did seems to work so far.