b748e9773f
When cliking on the "Delete attachment" link, and opening the URL in a new tab, the `DELETE /attachements/:id` will become `GET /attachments/:id` – which will cause the `show` action to be routed with an html format (instead of JS). In that case, we don't want to throw an error at the user face. Instead simply re-render the dossier page (if any). Fix a long-standing error in Sentry.
21 lines
604 B
Ruby
21 lines
604 B
Ruby
class AttachmentsController < ApplicationController
|
|
before_action :authenticate_logged_user!
|
|
include ActiveStorage::SetBlob
|
|
|
|
def show
|
|
@attachment = @blob.attachments.find(params[:id])
|
|
@user_can_upload = params[:user_can_upload]
|
|
|
|
respond_to do |format|
|
|
format.js
|
|
format.html { redirect_back(fallback_location: @attachment.record&.dossier || root_path) }
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
attachment = @blob.attachments.find(params[:id])
|
|
@attachment_id = attachment.id
|
|
attachment.purge_later
|
|
flash.now.notice = 'La pièce jointe a bien été supprimée.'
|
|
end
|
|
end
|