From 33cda592517894dab81468b55be58343a548cebe Mon Sep 17 00:00:00 2001 From: iamrubydevi Date: Sun, 5 Nov 2023 12:44:08 +0530 Subject: [PATCH] Add a destroy action for aeroplane --- app/controllers/api/v1/aeroplanes_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/aeroplanes_controller.rb b/app/controllers/api/v1/aeroplanes_controller.rb index be4352c..3c3dbb6 100644 --- a/app/controllers/api/v1/aeroplanes_controller.rb +++ b/app/controllers/api/v1/aeroplanes_controller.rb @@ -33,7 +33,13 @@ def update # DELETE /aeroplanes/1 def destroy - @aeroplane.destroy! + @aeroplane = Aeroplane.find(params[:id]) + + if @aeroplane.destroy + render json: { message: 'Aeroplane deleted successfully' }, status: :no_content + else + render json: { error: 'Failed to delete aeroplane' }, status: :unprocessable_entity + end end private