接下来是tutorial on how to do a soft-delete,这很有效。但是,如果用户决定返回并重新激活帐户,那么最好的方法是什么?或者这也有维基吗?我找不到它。

最佳答案

查看您发布的教程链接,他们使用时间(deleted)来确定用户是否被删除(软删除)。
如果登录凭据正确,现在可以使用单独的路由和方法重新激活用户我称之为“我的重新激活用户”

# app/models/user.rb

  # instead of deleting, indicate the user requested a delete & timestamp it
  def soft_delete
    update_attribute(:deleted_at, Time.current)
  end

  def reactivate_user
    update_attribute(:deleted_at, nil)
  end
  # ensure user account is active
  def active_for_authentication?
    super && !deleted_at
  end

  # provide a custom message for a deleted account
  def inactive_message
    !deleted_at ? super : :deleted_account
  end

关于ruby-on-rails - Rails 4 Devise重新激活“软删除”帐户,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34981626/

10-12 22:33