smpallen99 / ex_admin

ExAdmin is an auto administration package for Elixir and the Phoenix Framework
MIT License
1.2k stars 273 forks source link

Custom actions redirect #380

Open dmytronasyrov opened 7 years ago

dmytronasyrov commented 7 years ago

I have set a custom delete action for one of models. Same as in this article: article But instead of index GET redirection it sends DELETE. Any idea how to explicitly set GET verb to redirect to? I have tried to explicitly set GET into conn, so conn doesn't have any "delete" inside:

conn = %{conn | method: "GET"}
|> Plug.Conn.put_private(:phoenix_action, :get)
|> Plug.Conn.assign(:defn, nil)
|> Plug.Conn.assign(:request_path, "/admin/groups_images")
|> Phoenix.Controller.redirect(to: admin_resource_path(conn, :index))

Result is the same without any changes into conn, just with redirect. But redirect is still going into DELETE (without :id parameter)

[info] Sent 302 in 3ms
[info] DELETE /admin/groups_images
[debug] ** (Phoenix.Router.NoRouteError) no route found for DELETE /admin/groups_images (Admin.Router)
dmytronasyrov commented 7 years ago

Solved Plug.Conn.put_status(conn, 303)

Note: RFC 1945 and RFC 2068 specify that the client is not allowed to change the method on the redirected request. However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method. The status codes 303 and 307 have been added for servers that wish to make unambiguously clear which kind of reaction is expected of the client.