开发者

Rails: Delete User without losing associations (or other methods of letting Users leave)

开发者 https://www.devze.com 2023-02-13 00:20 出处:网络
I have a Rails application that lets Users create various \"judgements\", everything is a bit interweaved, we have several classes that are connected to the User class.

I have a Rails application that lets Users create various "judgements", everything is a bit interweaved, we have several classes that are connected to the User class.

When I let users "destroy" their account, obviously the associations they had will give me a nil object. So, for example, when I traverse all judgements, I can't get the user that created the judgeme开发者_StackOverflow社区nt if this particular user deleted (destroyed) their account.

  • What are the best practices in Rails for such cases?
  • Is it considered okay to flag a user as inactive, but still keep their account?
  • Could I delete the User account and replace the associated information in other classes?


This is really up to you and what works best for your application. It's not really a matter of what the Rails standard is as what the web-standard is. What would you expect to happen if you removed your account and you were a user of your application? Here are a couple of options:

  • Flag the account as inactive, keep the user's name and minimal profile.
  • Remove the user's account, but associate all related objects to an 'anonymous' or 'deleted user' account.
  • Remove all associated information.

Keep in mind that how you choose to proceed can also depend on the Terms of Service that your users have to agree to when using the site. If you have a right to keep their content you may be able to keep the associated information around, but it might be a good idea to remove their names and private information. It's probably best to consult a lawyer about the amount of data you can actually keep around. If you have free reign over the data, I would say go with what makes your users happy.

0

精彩评论

暂无评论...
验证码 换一张
取 消