Rails: removing a user without losing associations (or other ways to allow users)

I have a Rails application that allows users to create various β€œjudgments”, everything is a bit interwoven, we have several classes that are associated with the User class.

When I allow users to β€œdestroy” their account, it is obvious that the associations they have will give me an object nil. So, for example, when I look through all the judgments, I can’t get the user who created the solution if this particular user deleted (destroyed) his account.

  • What are the best practices in Rails for such cases?
  • Is it possible to consider the user inactive, but keep your account?
  • Can I delete a user account and replace related information in other classes?
+3
source share
1 answer

It really is up to you and what works best for your application. It is not a question of what the Rails standard is what the web standard is. What would you expect if you deleted your account and you were a user of your application? Here are a few options:

  • Mark the account as inactive, save the username and minimum profile.
  • Delete the user account, but associate all related objects with the anonymous or remote user account.
  • Delete all related information.

, , , , . , , . , , . , , , .

+8

Source: https://habr.com/ru/post/1793654/


All Articles