我刚刚创建了一个安装了 Devise 插件的示例应用程序。在我的用户模型中,我使用了 :token_authenticatable
,但是无论什么原因,在我创建用户时,它都会将 authentication_token
列作为 NULL
创建。
看起来你需要在创建新用户时设置 u.ensure_authentication_token!
来生成令牌。
我有遗漏什么吗?还是需要重写 Devise 的代码?
我刚刚创建了一个安装了 Devise 插件的示例应用程序。在我的用户模型中,我使用了 :token_authenticatable
,但是无论什么原因,在我创建用户时,它都会将 authentication_token
列作为 NULL
创建。
看起来你需要在创建新用户时设置 u.ensure_authentication_token!
来生成令牌。
我有遗漏什么吗?还是需要重写 Devise 的代码?
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable #...etc
before_save :ensure_authentication_token
end
这是一个设备方法,它将设置你的authentication_token。
rails generate mongo_mapper:devise User
和你的代码有什么不同,可能只是缺少了一个简单的包含语句。 - Jesse Wolgamott