Rails 4 Devise重新激活“软删除”帐目 [英] Rails 4 Devise reactivate "soft deleted" accounts
本文介绍了Rails 4 Devise重新激活“软删除”帐目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
遵循此有关如何执行软删除的教程,该方法有效。但是,如果用户决定要返回并重新激活帐户,那么最好的方法是什么?还是为此有一个Wiki?我找不到它。
Followed this tutorial on how to do a soft-delete, which works. But if a user decides they want to go back and reactivate the account, what would be the best way to do so? Or is there a wiki for this as well? I couldn't find it.
推荐答案
看着您发布的教程链接,他们使用时间(deleted_at)来确定是否用户已被删除(软删除)。
Looking at the tutorial link you posted, they used time (deleted_at) to determine if a user is deleted (soft-delete).
现在,如果登录凭据正确,您可以使用另一种方法和方法重新激活用户,我称我为 reactivate_user
You can now have a separate route and method for re-activating a user if the login credentials are correct i call mine reactivate_user
# 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
这篇关于Rails 4 Devise重新激活“软删除”帐目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文