Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devise_token_auth 1.1.0 installation fails with "undefined method 'devise' for User" #1276

drj17 opened this issue Mar 31, 2019 · 8 comments


Copy link

@drj17 drj17 commented Mar 31, 2019

When posting issues, please include the following information to speed up the troubleshooting process:

  • Version: 1.1.0
  • Rails Version: 5.2.3
  • Rails Stacktrace:
rake aborted!
NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection):Class
/app/models/user.rb:8:in `include'
/app/models/user.rb:8:in `<class:User>'
/app/models/user.rb:3:in `<main>'
/config/routes.rb:2:in `block in <main>'
/config/routes.rb:1:in `<main>'
/config/environment.rb:5:in `<main>'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)

Given the current installation settings in the documentation, installation fails in a brand new rails project.

@drj17 drj17 changed the title devise_token_auth 1.1.0 is unusable, fails with "undefined method 'devise' for User" devise_token_auth 1.1.0 installation fails with "undefined method 'devise' for User" Mar 31, 2019
Copy link

@vinhkq vinhkq commented Apr 2, 2019

You can add extend Devise::Models in User.rb Model.
It fixed for me.

Copy link

@dks17 dks17 commented Apr 6, 2019

This is Devise issue, but not the gem. And this is a Stack Overflow question.

ActiveRecord ORM was hard coded inside of the gem before. Now you must follow by Devise configuration.

  # ==> ORM configuration
  # Load and configure the ORM. Supports :active_record (default) and
  # :mongoid (bson_ext recommended) by default. Other ORMs may be
  # available as additional gems.
  require 'devise/orm/<%= options[:orm] %>'

Check also the gem doc.

Copy link

@jeffjiang0613 jeffjiang0613 commented Apr 14, 2019

I have met with the same issue in version 1.1.0, when I change the devise_token_auth to previous version 1.0.0, it works.

Copy link

@drj17 drj17 commented Apr 14, 2019

I would argue this is not a devise issue because you cannot install this gem with the readme as is. Perhaps someone would like to make that pull request? I could do it one I get access to a computer

Copy link

@reneclavijo reneclavijo commented Apr 17, 2019

I had the same issue, and just with 1.0.0 version works fine. If I use extend Devise::Models in User.rb raise an error with /auth/sign_in (creating sessions)

Copy link

@CDimonaco CDimonaco commented May 21, 2019

The update to the latest version should be documented in a better way, the way to go is create an initializer for devise and load active record, like @drj17 said, the changelog of this gem does not mention the upgrade step, and does not mention the new devise dependency.

I think we should definitely put something in the installation documentation, or at least an 'upgrade' section in the gem docs.

mc-chinju added a commit to mc-chinju/qiita_clone that referenced this issue Jun 14, 2019
aaaaninja pushed a commit to aaaaninja/happy_trigger that referenced this issue Aug 15, 2019

こんなバグが現在ある, ので提示されていた解決法をやった.

                   Prefix Verb   URI Pattern                                                                              Controller#Action
         new_user_session GET    /auth/sign_in(.:format)                                                                  devise_token_auth/sessions#new
             user_session POST   /auth/sign_in(.:format)                                                                  devise_token_auth/sessions#create
     destroy_user_session DELETE /auth/sign_out(.:format)                                                                 devise_token_auth/sessions#destroy
        new_user_password GET    /auth/password/new(.:format)                                                             devise_token_auth/passwords#new
       edit_user_password GET    /auth/password/edit(.:format)                                                            devise_token_auth/passwords#edit
            user_password PATCH  /auth/password(.:format)                                                                 devise_token_auth/passwords#update
                          PUT    /auth/password(.:format)                                                                 devise_token_auth/passwords#update
                          POST   /auth/password(.:format)                                                                 devise_token_auth/passwords#create
 cancel_user_registration GET    /auth/cancel(.:format)                                                                   devise_token_auth/registrations#cancel
    new_user_registration GET    /auth/sign_up(.:format)                                                                  devise_token_auth/registrations#new
   edit_user_registration GET    /auth/edit(.:format)                                                                     devise_token_auth/registrations#edit
        user_registration PATCH  /auth(.:format)                                                                          devise_token_auth/registrations#update
                          PUT    /auth(.:format)                                                                          devise_token_auth/registrations#update
                          DELETE /auth(.:format)                                                                          devise_token_auth/registrations#destroy
                          POST   /auth(.:format)                                                                          devise_token_auth/registrations#create
      auth_validate_token GET    /auth/validate_token(.:format)                                                           devise_token_auth/token_validations#validate_token
             api_v1_posts GET    /api/v1/posts(.:format)                                                                  api/v1/posts#index
                          POST   /api/v1/posts(.:format)                                                                  api/v1/posts#create
              api_v1_post GET    /api/v1/posts/:id(.:format)                                                              api/v1/posts#show
                          PATCH  /api/v1/posts/:id(.:format)                                                              api/v1/posts#update
                          PUT    /api/v1/posts/:id(.:format)                                                              api/v1/posts#update
                          DELETE /api/v1/posts/:id(.:format)                                                              api/v1/posts#destroy
       rails_service_blob GET    /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
rails_blob_representation GET    /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
       rails_disk_service GET    /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
update_rails_disk_service PUT    /rails/active_storage/disk/:encoded_token(.:format)                                      active_storage/disk#update
     rails_direct_uploads POST   /rails/active_storage/direct_uploads(.:format)                                           active_storage/direct_uploads#create
Copy link

@dkniffin dkniffin commented Oct 18, 2019

Any progress on this? I'm running into the same issue. @Tiltorito I see you opened a PR but the tests were failing. To me it looks like the reason was an intermittent issue with Travis. You could try restarting the build and that might fix it, but I could be way off base.

Copy link

@udit99 udit99 commented Aug 18, 2021

Ran into the same issue. Things that didnt work for me:

  1. Adding extend Devise::Models in User.rb
  2. rails generate devise:install after getting the error.

What worked for me:

  1. Rollback any changes files/migrations made by the devise_token_auth. Get to a state where your app has never heard of this gem.
  2. Before doing anything with devise_token_auth, first install devise by adding to Gemfile and running bundle install
  3. Run rails generate devise:install as per devise's installation instructions
  4. This will generate 2 files: config/initializers/devise.rb and config/locales/devise.en.yml
  5. Now start with devise_token_auth instructions by adding to Gemfile/bundle install/running the generator (rails g devise_token_auth:install User auth)

If this is the best way to solve this problem, I'd be happy to create a PR for the docs, but sounds like there are a lot of ways to skin this cat and not all of them work for everyone

EvitanRelta added a commit to EvitanRelta/cvwo-holiday-assignment that referenced this issue Jan 11, 2022
EvitanRelta added a commit to EvitanRelta/cvwo-holiday-assignment that referenced this issue Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants