2012-01-12 16 views
13

Tôi đã tạo Mô hình người dùng bằng cách sử dụng, nhưng bây giờ tôi muốn thêm hỗ trợ cho token_authenticable, vì vậy tôi cần phải di chuyển các bổ sung này. Chính xác như sau và loại token_authenticatable sẽ là gì?Thêm token_authenticatable để phát sinh khi di chuyển

class AddAuthenticationTokenToUser < ActiveRecord::Migration 

    def change 

    add_column :users, :token_authenticatable 
    add_index :users, :authentication_token, :unique => true 

    end 

end 

Trả lời

13
add_column :users, :token_authenticatable, :string 

Đừng quên để thêm devise :token_authenticatable để mô hình người dùng của bạn.

+0

Cảm ơn. Nhiều đánh giá cao. – Undistraction

+2

Kiểu lược đồ này đã được thay đổi trong phiên bản 2.0. Tên cột phải là 'authentication_token'. https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style –

+0

'rails g migration AddAuthenticationTokenToUser token_authenticatable: string: uniq' – Barry

2

Danh sách đầy đủ của những người giúp đỡ xóa cho sự di cư trong devise 2 như sau:

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 

Taken từ devise wiki

Các vấn đề liên quan