Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise: authentication_token column in user model is null

I just created a sample application with devise plugin installed. I have :token_authenticatable in my user model but for some reason when I create a user it creates it with authentication_token column as NULL.

It looks like you need to set u.ensure_authentication_token! when creating a new user to generate a token.

Am I missing something or I need to override devise's code?

like image 313
ed1t Avatar asked Mar 23 '11 01:03

ed1t


1 Answers

In your user class, just add

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable #...etc
  before_save :ensure_authentication_token
end

that's a devise method that will set your authentication_token.

like image 116
Jesse Wolgamott Avatar answered Oct 19 '22 16:10

Jesse Wolgamott