Devise_token_auth冲突? [英] Devise_token_auth conflicts?
问题描述
使用默认的--api标签在rails 5中制作新的API,并使用命令
rails安装devise_token_auth gem。在执行
rake:db:migrate
时,我得到此错误未定义的方法'devise',用于用户(调用'User.connection'建立连接)
这很奇怪,因为devise_token_auth建立在devise之上。
Made a new API in rails 5 using default --api tag and installed devise_token_auth gem using command
rails generate devise_token_auth:install User auth
. On doing rake:db:migrate
, I get this error undefined method 'devise' for User (call 'User.connection' to establish a connection)
which is weird because devise_token_auth is built on top of devise..
因此,注释掉路由会向包含
So, commenting out routes throws error to user.rb file containing
devise:database_authenticatable,:registerable,
:recoverable,:rememberable,:trackable,:validatable,:omniauthable
包括DeviseTokenAuth :: Concerns :: User
在注释掉这些行之后,它向包含以下内容的应用程序控制器抛出错误:
include DeviseTokenAuth :: Concerns :: SetUserByToken
注释掉这一行后,我收到了devise:orm错误。
After commenting those lines out it throws error to application controller containing:
include DeviseTokenAuth::Concerns::SetUserByToken
After commenting out this line, I get the devise:orm error.
也尝试将devise添加到gemfile并为用户安装devise,但也失败了,再次抛出此错误 User的未定义方法 devise(调用 User.connection以建立连接)
Also tried adding devise to gemfile and installing devise for users, which failed too, throwing this error again undefined method 'devise' for User (call 'User.connection' to establish a connection)
预期要进行的迁移
遇到设计错误
应采取的措施这是
PS-这是我使用Devise_token_auth gem制作的第三个API,之前没有遇到此问题
PS- This was a third API I'm making using Devise_token_auth gem, didn't face this issue earlier
推荐答案
这是一个设计问题,ActiveRecord ORM已在gem内进行了硬编码,现在已对其进行了更改。可以通过创建和添加下面的文档中提到的devise初始化程序来解决。
This is a devise Issue, ActiveRecord ORM was hard coded inside of the gem before which has been changed now. This can be resolved by creating and adding the devise initializer as mentioned in the below documentation.
https://devise-token-auth.gitbook.io/devise-token-auth/config/initialization
还有另一种解决方法,可以在user.rb模型文件中添加以下内容。
There is also another way of fixing this, by adding the following in your user.rb model file.
extend Devise::Models
devise_token_auth中还有一个未解决的问题
There is also an open issue in devise_token_auth
https://github.com/lynndylanhurley/devise_token_auth / issues / 1276
在哪里可以跟进此问题/添加您的想法以解决此问题。
Where you can follow up regarding this issue / Add in your thoughts for resolving this.
这篇关于Devise_token_auth冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!