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。但运行耙分贝时:迁移我得到以下

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

我已经运行下面一行

rails g devise:install 

任何理由色器件将无法识别它,做我需要做的话要说客户一个设计? 在此先感谢

+0

您是否将“设计”gem添加到您的Gemfile中,然后运行“捆绑安装”?只是一个确认:) – 2012-08-14 14:25:12

+0

是的,我做了,但我看到没有帮手参与。我应该担心这些吗? – Jseb 2012-08-14 14:26:08

+0

马克正确答案! – retro 2012-08-14 16:18:10

回答

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 2012-08-14 14:35:19

+0

不需要。自己尝试一个虚拟项目:)此外,您可以访问[设计2.0文档](https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0 -migration-schema-style) – 2012-08-14 14:37:35

+0

感谢它现在的作品,现在我需要学习设计并正确使用它 – Jseb 2012-08-14 14:39:36