Ruby on rails 从现有模型/数据库设计安装

Ruby on rails 从现有模型/数据库设计安装,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.1,devise,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.1,Devise,我想知道如何将Desive添加到具有不同用户的现有数据库中。在这里,我已经定义了一个客户模型,我想更改以允许Desive处理它 我已经创建了一个新的迁移,并插入了下面的代码 class AddDeviseToCustomer < ActiveRecord::Migration def change change_table :customers do |t| #t.database_authenticatable t.string :encrypted_

我想知道如何将Desive添加到具有不同用户的现有数据库中。在这里,我已经定义了一个客户模型,我想更改以允许Desive处理它

我已经创建了一个新的迁移,并插入了下面的代码

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
任何理由Desive都不会认出它,我需要做些什么来说明客户是Desive吗??
提前感谢

看起来文档已经过时了

尝试使用Desive generator,它将创建相同的迁移,参数正确,如果是现有模型,则可以:

rails g devise customer
它应该创建
addDevisionToCustomers
迁移

与此类似:

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
class AddDevisionToCustomersfalse,:default=>
t、 字符串:加密密码,:null=>false,:default=>
##可恢复
t、 字符串:重置密码\u令牌
t、 日期时间:重置密码发送时间
##难忘的
t、 datetime:记住在
##可追踪
t、 整数:计数中的符号,默认值=>0
t、 日期时间:当前登录时间
t、 日期时间:上次登录时间
t、 字符串:ip中的当前\u符号\u
t、 字符串:ip中的最后\u签名\u
##可证实
t、 字符串:确认令牌
t、 日期时间:已确认
t、 日期时间:确认发送至
t、 字符串:未确认的电子邮件#仅当使用可再确认
##可锁
#t.integer:failed_尝试,:default=>0#仅当锁定策略为:failed_尝试时
#t.string:unlock_token#仅当解锁策略为:email或:两者皆有时
#t.datetime:locked_在
##可认证令牌
#t.string:authentication\u令牌
#如果原始模型中未包含时间戳,请取消下面的注释。
#时间戳
结束
def自动关闭
#默认情况下,我们不希望在您的
#模型已经存在。请在下面编辑要在此迁移中删除的字段。
raise ActiveRecord::不可逆迁移
结束
结束

请注意,没有更多的
t.confirmable

您是否将“设计”gem添加到您的gem文件中,然后运行“捆绑安装”?只是一个确认:)是的,我做了,但我看到没有助手参与。我应该担心这些吗?它会删除我当前的用户吗?不会。你自己在一个虚拟项目中尝试:)此外,你可以访问我很高兴它确实有帮助。确保您正在阅读Desive 2.0文档。祝你好运。是的,拉胡尔,它应该会起作用。但别忘了从生成的迁移文件中删除电子邮件字段。@AlperKarapınar为什么不更改它而不是删除它?像这样
t.change:email,:string,null:false,默认值:“
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