我已经使用设计创建了一个用户模型,但我现在想添加对token_authenticable的支持,所以我需要迁移这些添加。以下是否正确,token_authenticatable应该是什么类型?
class AddAuthenticationTokenToUser < ActiveRecord::Migration
def change
add_column :users, :token_authenticatable
add_index :users, :authentication_token, :unique => true
end
end
答案 0 :(得分:17)
答案 1 :(得分:13)
add_column :users, :token_authenticatable, :string
不要忘记将devise :token_authenticatable
添加到您的用户模型中。
答案 2 :(得分:2)
设计2中已删除的迁移助手的完整列表如下:
create_table(TABLE_NAME) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Encryptable
# t.string :password_salt
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
# Token authenticatable
# t.string :authentication_token
## Invitable
# t.string :invitation_token
t.timestamps
end