Rails 4 Devise重新激活“软删除”帐目

编程入门 行业动态 更新时间:2024-10-26 08:27:34
本文介绍了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重新激活“软删除”帐目

本文发布于:2023-10-26 09:24:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529755.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:帐目   Rails   Devise

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!