【问题标题】:Devise - cant add confirmation functionality设计 - 无法添加确认功能
【发布时间】:2015-04-16 20:29:34
【问题描述】:

我知道以前有人问过这个问题,但没有一个答案对我有帮助。

我有以下情况。

  • 我安装了设计(一切正常)
  • 想要包含确认邮件,所以我愿意

    1. 包括:在用户模型中可确认
    2. 取消注释我的迁移文件中的相关行(请参阅下面的整个文件)。
    3. 运行 rake db:migrate(并重新启动服务器)

当我现在尝试注册时,我得到“” X 的未定义局部变量或方法 `confirmed_at'....

我在这里错过了什么?

类 DeviseCreateUsers

  ## 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, null: false
  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, null: false # Only if lock strategy is :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at


  t.timestamps
end

add_index :users, :email,                unique: true
add_index :users, :reset_password_token, unique: true
add_index :users, :confirmation_token,   unique: true
# add_index :users, :unlock_token,         unique: true

结束 结束

【问题讨论】:

  • 我不确定,但其中的代码是 t.confirmable 丢失或可能存在具有相同文件名的相同迁移,因此请尝试添加不同名称的迁移文件

标签: ruby-on-rails ruby


【解决方案1】:

您说,您更改了迁移并重新运行rake db:migrate。
更改已迁移的迁移不是一个好主意。
Rails 不会协调迁移中的更改。因此,除非您真的知道,您的上一次迁移尚未部署或签入,并且当前表中的所有数据都可以丢弃不要更改迁移。

而是创建一个添加新字段的新迁移。

如果您真的知道自己在做什么,您可以回滚上次(甚至是视图)迁移,更改它然后再次运行:

rake db:rollback STEP=1
# edit your migration
rake db:migrate

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    相关资源
    最近更新 更多