diff --git a/app/components/attachment/edit_component.rb b/app/components/attachment/edit_component.rb index a0dc0d3d6..117ea2a8c 100644 --- a/app/components/attachment/edit_component.rb +++ b/app/components/attachment/edit_component.rb @@ -55,7 +55,7 @@ class Attachment::EditComponent < ApplicationComponent end def destroy_attachment_path - attachment_path(champ: @champ) + attachment_path(dossier_id: champ&.dossier_id, stable_id: champ&.stable_id, row_id: champ&.row_id) end def attachment_input_class diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 4e53e804f..721ec2cc2 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -21,11 +21,18 @@ class AttachmentsController < ApplicationController @attachment.purge_later flash.notice = 'La pièce jointe a bien été supprimée.' - @champ = Champ.find(params[:champ]) if params[:champ] + @champ = find_champ if params[:dossier_id] respond_to do |format| format.turbo_stream format.html { redirect_back(fallback_location: root_url) } end end + + private + + def find_champ + dossier = policy_scope(Dossier).includes(:champs).find(params[:dossier_id]) + dossier.champs.find_by(stable_id: params[:stable_id], row_id: params[:row_id]) + end end