8

다른 사용자와 기존 데이터베이스를 어떻게 추가 할 수 있을지 궁금합니다. 여기서 나는 이미 고객 모델 정의를 가지고 있으며, devise가 그것에 대해 작업 할 수 있도록 변경하려고합니다.기존 모델/데이터베이스에서 Devise를 설치하십시오.

나는 새로운 마이그레이션을 작성하고 삽입 된 코드는 작동합니다 이에 따라

class AddDeviseToCustomer < ActiveRecord::Migration 
    def change 
    change_table :customers do |t| 
     #t.database_authenticatable 
     t.string :encrypted_password, :null => false, :default => '', :limit => 128 
     t.confirmable 
     t.recoverable 
     t.rememberable 
     t.trackable 
     t.token_authenticatable 
     t.timestamps 
    end 
    end 
end 

따라이있다. https://github.com/plataformatec/devise/wiki/How-To:-change-an-already-existing-table-to-add-devise-required-columns. 갈퀴 DB를 실행 때 : 내가 나는 어떤 이유 유증이 그것을 인식하지 않습니다 다음 줄

rails g devise:install 

를 실행 한

undefined method `confirmable' for #<ActiveRecord::ConnectionAdapters::Table:0x9286a28> 

다음 얻을 마이그레이션 난 고객이 말이 어떻게해야합니까 장치? 미리 감사드립니다.

+0

"devise"gem을 Gemfile에 추가 한 다음 "bundle install"을 실행 했습니까? 그냥 확인 :) –

+0

예,하지만 내가 도우미가 관련된 것을 참조하십시오. 이것들에 대해 걱정해야합니까? – Jseb

+0

정답을 표시하십시오! – retro

답변

17

문서가 오래된 것 같습니다.

, 그것은 올바른 매개 변수와 함께, 그것의 경우 기존 모델 괜찮아, 같은 마이그레이션을 만들 것입니다 유증 생성기를 사용해보십시오 :이 비슷한으로 AddDeviseToCustomers 마이그레이션

을 만들어야합니다

rails g devise customer 

:

더 이상이 없음을 는
class AddDeviseToCustomers < ActiveRecord::Migration 
def self.up 
change_table(:customers) 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 

    ## 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 


    # Uncomment below if timestamps were not included in your original model. 
    # t.timestamps 
end 

def self.down 
# By default, we don't want to make any assumption about how to roll back a migration when your 
# model already existed. Please edit below which fields you would like to remove in this migration. 
raise ActiveRecord::IrreversibleMigration 
end 
end 

참고 t.confirmable

+0

내 현재 사용자가 지워 집니까? – Jseb

+0

아니요. 더미 프로젝트에서 직접 해보십시오. :) [개발자 2.0 문서는 여기에 있습니다.] (https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0)에 액세스 할 수 있습니다. -migration-schema-style) –

+0

고마워 이제는 고안을 배우고 올바르게 사용해야합니다. – Jseb

관련 문제