devise_token_auth
devise_token_auth copied to clipboard
devise_token_auth 1.1.0 installation fails with "undefined method 'devise' for User"
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
You can add extend Devise::Models
in User.rb
Model.
It fixed for me.
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.
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.
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
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)
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.
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.
Ran into the same issue. Things that didnt work for me:
- Adding
extend Devise::Models
in User.rb -
rails generate devise:install
after getting the error.
What worked for me:
- Rollback any changes files/migrations made by the devise_token_auth. Get to a state where your app has never heard of this gem.
- Before doing anything with
devise_token_auth
, first installdevise
by adding to Gemfile and runningbundle install
- Run
rails generate devise:install
as per devise's installation instructions - This will generate 2 files:
config/initializers/devise.rb
andconfig/locales/devise.en.yml
- 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
The approuch of @udit99 worked. Another workflow can be:
- comment Device code reference in
models/user.rb
andconfig/routes.rb
- run
rails generate devise:install
. It should generate the initialization that we need. - Rollback the step 1.
I think should include the Device initialization in the documentation.
Thanks @udit99
Thank you @udit99 and @Luiyit you're steps worked. So then, is it necessary to run rails generate devise:install
before rails generate devise_token_auth
install?
Or maybe that is not ideal because that will install a bunch of Devise stuff that is not needed for token auth? Just need a way to generate the config/initializers/devise.rb
file, correct?
Hi @johnpitchko. I think so. You can run devise_token_auth
first, but you will get the error, for that reason in this case we need to comment model files (on my steps) or rollback migration files (on audit99's steps).
I think the correct step by stem should be (from scratch)
- Add
device_token_auth
gem to.gemfile
- Run
rails generate devise:install
- Follow current
device_token_auth's
installation instructions