Skip to content

Commit

Permalink
find champ by dossier stable_id row_id
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit-MINT committed Jul 8, 2024
1 parent fc38520 commit ebea9e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/components/attachment/edit_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def attachment_path(**args)
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
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/attachments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ def destroy
@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

0 comments on commit ebea9e3

Please sign in to comment.