ruby-on-rails - 添加设备:confirmable to 2 models

标签 ruby-on-rails ruby devise database-migration devise-confirmable

有人能给我一个如何使用现有数据库将设备添加到 2 个不同模型的示例吗?我有 2 个模型,客户和供应商。如果我只是在两个模型上添加 :confirmable 并进行迁移 rails g 迁移add_confirmable_to_devise 迁移数据库后,两个模型中都会包含可确认选项吗?

最佳答案

不,您必须创建两个单独的迁移:

rails g 迁移 add_devise_fields_to_customer

class AddDeviseFieldsToCustomer < ActiveRecord::Migration
  def change
    # Confirmable columns
    add_column :customers, :confirmation_token, :string
    add_column :customers, :confirmed_at, :datetime
    add_column :customers, :confirmation_sent_at, :datetime
    add_column :customers, :unconfirmed_email, :string
  end
end

rails g 迁移 add_devise_fields_to_vendor

class AddDeviseFieldsToVendor < ActiveRecord::Migration
  def change
    # Confirmable columns
    add_column :vendors, :confirmation_token, :string
    add_column :vendors, :confirmed_at, :datetime
    add_column :vendors, :confirmation_sent_at, :datetime
    add_column :vendors, :unconfirmed_email, :string
  end
end

这只是针对可确认的,因为这是您指定的模块。如果您需要其他设计模块(Trackable、DatabaseAuthenticatable 等),您也需要将这些列添加到迁移中。

您还必须将 :confirmable (以及您想要的任何其他功能)添加到模型本身。

关于ruby-on-rails - 添加设备:confirmable to 2 models,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37111502/

相关文章:

ruby-on-rails - 如何将当前user_id自动添加到另一个表中?

ruby-on-rails - 在 Rails 中使用 Eco 模板引擎

ruby-on-rails - 嵌入 Ruby 时在 Sublime Text 2 中保留 Sass 语法高亮

ruby - 当包含在 gemfile 中/在应用程序中需要时, "take over"是如何神奇地变薄的?

ruby - rvm use 1.9.2 让我使用 ruby​​ 1.8.7

ruby-on-rails - 为什么 Devise + Omniauth 回调没有命中正确的 Controller ?

javascript - 带有 highcharts 的 javascript 中的日期/时间问题

ruby-on-rails - 如果 open-uri 有效,为什么 net/http 返回一个空字符串?

python - 等价于 Python 中的 Ruby nil 数组

ruby-on-rails - Rails3 + Devise : edit_password_url spits out http//www. blah.com(没有冒号 http!)