Class: Collavre::AttachmentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/collavre/attachments_controller.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject

DELETE /attachments/:signed_id



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/collavre/attachments_controller.rb', line 4

def destroy
  blob = ActiveStorage::Blob.find_signed(params[:signed_id])

  unless authorized_to_purge?(blob)
    return head :forbidden
  end

  blob.purge
  head :no_content
rescue ActiveRecord::RecordNotFound
  head :not_found
rescue StandardError => e
  Rails.logger.error("Failed to delete attachment: #{e.message}")
  head :internal_server_error
end