Topic: Redirect After Delete [SOLVED]

I have several cases where I want to do a redirect after a DELETE. From the browser's point of view the interaction looks correct - the DELETE is issued, a 302 is returned pointing at the correct redirect URL, and the browser issues a GET on that URL. However on the Rails side, Rails appears to be trying to do a DELETE on the redirect URL.

The path the DELETE is issued on might look like this:

user_authorization_path(@user, authorization)

The redirect in my controller might look like this:

redirect_to edit_user_path(params[:user_id])

My browser's debugger sees this:

Request URL:http://localhost:3000/users/1/authorizations/12
Request Method:DELETE
Status Code:302 Found

Request URL:http://localhost:3000/users/1/edit
Request Method:GET
Status Code:404 Not Found

Rails' log shows this:

Started DELETE "/users/1/authorizations/12"...
...
Redirected to http://localhost:3000/users/1/edit
Completed 302 Found in 8ms (ActiveRecord: 0.2ms)

Started DELETE "/users/1/edit"...

ActionController::RoutingError (No route matches DELETE "/users/1/edit")

Manually doing a GET on the redirect URL works fine.

Does Rails not support delete-redirect-get? Thoughts on what the problem could be? Thanks.

Last edited by SingleShot (2013-01-31 14:30:34)

Re: Redirect After Delete [SOLVED]

For posterity, this hack is what was required for the above example:

  resources :users
  delete 'users/:id/edit' => 'users#edit', :via => :get

For whatever reason, rails is stuck on using the DELETE verb after a DELETE redirect, even though the browser specifically uses GET. This hack tells rails to use GET whenever it DELETEs the users/edit resource. I consider this hack a workaround to a bug in rails.

Last edited by SingleShot (2013-01-31 14:31:34)