设计:用户模型中的authentication_token列为空

ed1*_*d1t 7 ruby authentication ruby-on-rails devise ruby-on-rails-3

我刚刚创建了一个安装了devise插件的示例应用程序.我有:token_authenticatable我的用户模型,但出于某种原因,当我创建一个用户时,它创建它与authentication_token列为NULL.

看起来您需要u.ensure_authentication_token!在创建新用户时设置以生成令牌.

我错过了什么或者我需要覆盖设计代码吗?

Jes*_*ott 17

在您的用户类中,只需添加即可

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable #...etc
  before_save :ensure_authentication_token
end
Run Code Online (Sandbox Code Playgroud)

这是一个设置authentication_token的设计方法.