ruby-on-rails – 设计身份验证令牌
发布时间:2020-12-16 19:13:45 所属栏目:百科 来源:网络整理
导读:在设计中,我如何访问用户的身份验证令牌.当ajax调用启动用户会话时,我需要能够从用户那里获取身份验证令牌.我尝试过在我的模型中添加:token_authenticable devise :database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validat
在设计中,我如何访问用户的身份验证令牌.当ajax调用启动用户会话时,我需要能够从用户那里获取身份验证令牌.我尝试过在我的模型中添加:token_authenticable
devise :database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatable 还添加了名称的属性,例如:authentication_token和:authenticity_token到attr_accessible.但每当我尝试用user.auth调用authentication_token或者authenticity_token时,我会收到像这样的错误 NoMethodError: undefined method `authentication_token' for #<User:0x000001016b1140> 对不起,我需要通过我的ajax调用来获取此令牌(我工作的最后一个项目,我有一个令人难以置信的BOOTLEG解决方案,其中设备几乎被撕掉了应用程序,我只需要这个该死的令牌) 解决方法
通过将:token_authenticatable模块包含到设计用户模型中来解决此问题:
devise :token_authenticatable,... 此方法也是在类本身上定义的,而不是实例.将其称为User.authentication_token. 见:https://github.com/plataformatec/devise/blob/master/lib/devise/models/token_authenticatable.rb#L61-63. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |