Sha256: ed7ad23d5e87bf740e77ce236f3c063fc8d5a7bf7bc24cd9b3707ef750876916

Contents?: true

Size: 736 Bytes

Versions: 1

Compression:

Stored size: 736 Bytes

Contents

module SoftDeletable
  extend ActiveSupport::Concern

# you need to put this in the model:
#  include InlineForms::SoftDeletable
#  enum deleted: { active: 1, deleted: 2 }

# you need a migration like this:
# class AddDeletedAtColumnToUser < ActiveRecord::Migration[6.0]
#   def change
#     add_column :users, :deleted_at, :datetime, default: nil
#     add_column :users, :deleted, :integer, default: 1
#     add_column :users, :deleted_by, :integer, default: nil
#   end
# end

  def soft_deletable?
    true
  end

  def soft_delete(current_user)
    deleted = 2
    deleter = current_user
    deleted_at = Time.current
    save
  end

  def soft_restore
    deleted = 1
    deleted_by = nil
    deleted_at = nil
    save
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inline_forms-6.0.3 app/models/concerns/inline_forms/soft_deletable.rb