Module: ActsAsArchived
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/acts_as_archived.rb
Overview
Each controller needs its own archive and unarchive action. To simplify this, use the following route concern.
In your routes.rb:
Rails.application.routes.draw do
acts_as_archived
resource :things, concern: :acts_as_archived
resource :comments, concern: :acts_as_archived
end
and include Effective::CrudController in your resource controller
Defined Under Namespace
Modules: ActiveRecord, ClassMethods, RoutesConcern
Instance Method Summary collapse
-
#archive! ⇒ Object
Instance methods.
- #destroy ⇒ Object
- #unarchive! ⇒ Object
Instance Method Details
#archive! ⇒ Object
Instance methods
71 72 73 74 75 76 |
# File 'app/models/concerns/acts_as_archived.rb', line 71 def archive! transaction do update!(archived: true) # Runs validations [:cascade].each { |obj| public_send(obj).update_all(archived: true) } end end |
#destroy ⇒ Object
85 86 87 |
# File 'app/models/concerns/acts_as_archived.rb', line 85 def destroy archive! end |
#unarchive! ⇒ Object
78 79 80 81 82 83 |
# File 'app/models/concerns/acts_as_archived.rb', line 78 def unarchive! transaction do update_column(:archived, false) # Does not run validations [:cascade].each { |obj| public_send(obj).update_all(archived: false) } end end |