Redirect from HTTP POST to HTTP DELETE from the routes

Hello,

I’m dealing with a bunch of old clients where they’re using a few POST requests for some actions that ideally would use DELETE requests.

I was able to redirect almost all of the POST requests with random URLs to nice rails routes, for example:

POST /add-item/ => POST /items/
GET /list-items/ => GET /items/


get "/list-items", to: redirect("/items")
post "/add-item", to: redirect("/items", status: :temporary_redirect)

resources :items

The issue I’m facing is with some POST requests being fired to delete items:

POST /delete-item/?item_id=1234

I’m not sure if it’s even possible to re-route POST requests to DELETE requests. All available options either use the same http method or redirect with a GET request.

Any options on how to deal with this issue?

Thanks.

One of these should do the trick:

post '/delete-item', to: redirect('/items', params: { _method: 'DELETE' })
post '/delete-item', to: redirect('/items', headers: { 'X-HTTP-Method-Override' => 'DELETE' })