8

मुझे आश्चर्य है कि मैं एक अलग उपयोगकर्ता के साथ मौजूदा डेटाबेस में कैसे डिज़ाइन कर सकता हूं। यहां मेरे पास पहले से ही एक ग्राहक मॉडल परिभाषित है और मैं उस पर काम करने की अनुमति देने के लिए बदलना चाहता हूं।मौजूदा मॉडल/डेटाबेस से स्थापित करें

मैं एक नया माइग्रेशन बनाया है और डाला कोड

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 चल: विस्थापित मैं निम्नलिखित

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

मैं निम्न पंक्ति

rails g devise:install 

किसी भी कारण वसीयत इसे पहचान नहीं होगा चलाने मिलता है, मैं कुछ कहने के लिए ग्राहक है क्या करना होगा एक देवता ?? अग्रिम धन्यवाद

+0

क्या आपने अपने Gemfile को "devise" मणि जोड़ा और फिर "बंडल इंस्टॉल" चलाया? बस एक पुष्टि :) –

+0

हाँ मैंने किया, लेकिन मुझे लगता है कि कोई सहायक शामिल नहीं है। क्या मुझे इनके बारे में चिंता करनी चाहिए? – Jseb

+0

सही उत्तर चिह्नित करें! – retro

उत्तर

17

ऐसा लगता है कि दस्तावेज पुराना है।

वसीयत जनरेटर का उपयोग की कोशिश करें, यह एक ही प्रवास पैदा करेगा, सही मापदंडों के साथ, यह ठीक है अगर इसकी एक मौजूदा मॉडल:

rails g devise customer 

यह इस के समान कुछ के साथ AddDeviseToCustomers प्रवास

बनाना चाहिए:

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

Woudl यह मेरे वर्तमान उपयोगकर्ता मिटा देता है? – Jseb

+0

नहीं। इसे अपने आप को एक डमी प्रोजेक्ट में आज़माएं :) इसके अलावा, आप [यहां 2.0 दस्तावेज़ तैयार करें] तक पहुंच सकते हैं (https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0 माइग्रेशन-स्कीमा-स्टाइल) –

+0

धन्यवाद यह अब काम करता है मुझे इसे सीखने और इसे ठीक से उपयोग करने की आवश्यकता है – Jseb

संबंधित मुद्दे