Module: WithUploads
- Extended by:
- ActiveSupport::Concern
- Includes:
- FastDestroyAll::Helpers
- Included in:
- AbuseReport, Appearance, BulkImports::ExportUpload, DesignManagement::Action, Group, ImportExportUpload, PersonalSnippet, Project, Projects::ImportExport::RelationExportUpload, User
- Defined in:
- app/models/concerns/with_uploads.rb
Overview
Mounted uploaders are destroyed by carrierwave’s after_commit hook. This hook fetches upload location (local vs remote) from Upload model. So it’s necessary to make sure that during that after_commit hook model’s associated uploads are not deleted yet. IOW we can not use dependent: :destroy : has_many :uploads, as: :model, dependent: :destroy
And because not-mounted uploads require presence of upload’s object model when destroying them (FileUploader’s ‘build_upload` method references `model` on delete), we can not use after_commit hook for these uploads.
Instead FileUploads are destroyed in before_destroy hook and remaining uploads are destroyed by the carrierwave’s after_commit hook.
Constant Summary collapse
- FILE_UPLOADERS =
Currently there is no simple way how to select only not-mounted uploads, it should be all FileUploaders so we select them by ‘uploader` class
%w[PersonalFileUploader NamespaceFileUploader FileUploader].freeze
Instance Method Summary collapse
Methods included from FastDestroyAll::Helpers
Methods included from AfterCommitQueue
#run_after_commit, #run_after_commit_or_now
Instance Method Details
#retrieve_upload(_identifier, paths) ⇒ Object
43 44 45 |
# File 'app/models/concerns/with_uploads.rb', line 43 def retrieve_upload(_identifier, paths) uploads.find_by(path: paths) end |