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, CanCan, ClassMethods, RoutesConcern
Instance Method Summary collapse
-
#archive! ⇒ Object
Instance methods.
- #destroy ⇒ Object
- #unarchive! ⇒ Object
Instance Method Details
#archive! ⇒ Object
Instance methods
80 81 82 83 84 85 |
# File 'app/models/concerns/acts_as_archived.rb', line 80 def archive! transaction do update!(archived: true) # Runs validations [:cascade].each { |obj| public_send(obj).update_all(archived: true) } end end |
#destroy ⇒ Object
94 95 96 |
# File 'app/models/concerns/acts_as_archived.rb', line 94 def destroy archive! end |
#unarchive! ⇒ Object
87 88 89 90 91 92 |
# File 'app/models/concerns/acts_as_archived.rb', line 87 def unarchive! transaction do update!(archived: false) [:cascade].each { |obj| public_send(obj).update_all(archived: false) } end end |