简体   繁体   中英

How to use “devise” gem in mongodb with rails 4 version?

I am using Rails 4 and MongoDB as a database for my project. I'm using the "devise" gem for creating logins, but I am not able to find a version of MongoMapper compatible with Rails 4. I'm getting the following error:

/app/models/user.rb:3:in `<class:User>': uninitialized constant MongoMapper::Devise (NameError),
rom /home/rails/Projects/synergy/app/models/user.rb:1:in `<top (required)>'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/inflector/methods.rb:226:in `const_get'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/inflector/methods.rb:226:in `block in constantize'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/inflector/methods.rb:224:in `each'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/inflector/methods.rb:224:in `inject'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/inflector/methods.rb:224:in `constantize'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise.rb:297:in `get'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise/mapping.rb:77:in `to'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise/mapping.rb:72:in `modules'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise/mapping.rb:89:in `routes'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise/mapping.rb:156:in `default_used_route'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise/mapping.rb:66:in `initialize'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise.rb:331:in `new'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise.rb:331:in `add_mapping'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise/rails/routes.rb:218:in `block in devise_for'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise/rails/routes.rb:217:in `each'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/lib/devise/rails/routes.rb:217:in `devise_for'
    from /home/rails/Projects/synergy/config/routes.rb:5:in `block in <top (required)>'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:341:in `instance_exec'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:341:in `eval_block'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:319:in `draw'
    from /home/rails/Projects/synergy/config/routes.rb:1:in `<top (required)>'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `each'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/file_update_checker.rb:75:in `call'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/file_update_checker.rb:75:in `execute'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `run'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/rails/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from /home/rails/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /home/rails/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from /home/rails/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from /home/rails/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from /home/rails/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from /home/rails/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/application.rb:215:in `initialize!'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/rails/Projects/synergy/config/environment.rb:5:in `<top (required)>'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/application.rb:189:in `require_environment!'
    from /home/rails/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.1/lib/rails/commands.rb:44:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>

How do I use MongoMapper with Rails 4?

The latest versions of devise seem to only have ORM support for mongoid and active record.

https://github.com/plataformatec/devise/tree/master/lib/devise/orm

There are some gems around which might help, but they are out of date and probably will not work with the latest devise/mongomapper.

If you have to use mongodb, then use the mongoid driver (instead of mongomapper), which is supported.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM