I recently came across an instance when I deleted a User from the database, but the index page for Posts broke because the User that wrote a specific post did not exist anymore.
This made me wonder whether it is good practice to always use :dependent => :destroy? Or is there a not-so-complicated alternative solution to not make the entire page break when the User is deleted? I guess it's more of a business decision, but I think I don't necessarily want to delete all the content when a User removes his account.
I suppose I could use something like
<%= link_to post.author.username unless post.author.blank? ...... %>
but that would make it a very tedious and messy task to have to include that in every line.
Any suggestions/tips on this matter?
Rather then deleting the user deactivate the user, this way you won't break any of the relationships and your data will remain consistent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With