Friday, 27 September 2019

Paranoia Gem for soft delete

Paranoia Gem

Paranoia is a gem that allows you to hide records instead of destroying them. You can recover them later if you want.

Follow these Steps:-

1.  Add the gem to your Gemfile and run bundle:
        gem 'acts_as_paranoid', '~> 0.6.0'
2.  Now you will need to add a migration to have a deleted_at column for the
     models that you want to have the archiving functionality.
        rails g migration add_deleted_at_to_posts deleted_at:datetime:index
     after that you can run rails db:migrate to add the column to the table
3.  Now all you have to do is add the method call acts_as_paranoid to the model  
     that you want the functionality added to, like this:
        class Post < ApplicationRecord
           acts_as_paranoid
        end
4.  https://www.dailysmarty.com/posts/how-to-soft-delete-in-rails( I use  
    this link to complete this task)

No comments:

Post a Comment

  Common Git Commands   Take clone of a repository git clone <remote-repository-url> ex: git clone  https://github.com/agricor/RegTech...