Yes, but paranoia uses default_scope, which many people don't recommend. Here is some good discussion on why: https://stackoverflow.com/q...
Hi Chris, Great video as always.
I'm trying to prevent the users avatar being fully deleted, when the soft delete occurs. I've read documentation to suggest that adding has_attached_file :avatar, preserve_files: true but this doesn't seem to work. I was hoping that you may have an idea why?
Hey Gareth, when you do a soft delete, there should be nothing that happens other than a database field called deleted_at getting set. This won't affect images at all because they should only get removed when destroyed. Are the images actually getting removed?
Would you be able to give some insight into how to really destroy a record using this gem.
Their documentation says "If you wish to actually destroy an object you may call really_destroy!. WARNING: This will also really destroy all dependent: :destroy records, so please aim this method away from face when using."
So I have it defined in my controller...but what I don't get is when I have the link in my view what method can I use to really destroy it?
Isn't method :destroy just going to try and soft delete it again?
Basically you can take let your normal destroy action call the soft delete method. You'll always want to use that by default.
Then, if you want to add a way to permanently delete it, you can add another route like:
resources :blog_posts do
And then your controller action for this new route can call
Right, so you'd have links to the two different delete urls like this:
<%= link_to "Soft Delete", blog_post_path(@blog_post), method: :delete %>
<%= link_to "Permanently Delete", really_destroy_blog_post_path(@blog_post), method: :delete %>
Hi guys iI need to use this gem but there is an issue with the dependent destroy.
eg: a has many b
paranoid is added to model a
I m able to restore record of a
but i lost all the associated record from model b
Is there a way to soft delete records of model b when I soft delete record of a.
You need to add soft delete on the b model. What I mean is, create a column `deleted_at` (or whatever you want since paranoia supports that option too) and call the class method `acts_as_paranoid` (also if you named your column different than `deleted_at` you should specify it here, just be sure to check the README https://github.com/rubysher... and then the destroy will be recursive on the associations.
What I mean is when you call `a.destroy` if you have `has_many :b, dependent: :destroy` then it will call `b.destroy` on all of the b models associated with model a
Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.