Unable to fix the "no route found for put" problem

Hello together, :wave:t3:

I’m pretty new to Elixir/Phoenix, and so far I’ve read a lot around here and could solve most problems by my own.
But here’s a problem I struggle with for hours now:

** (Phoenix.Router.NoRouteError) no route found for PUT /books (LibraryApiWeb.Router) RESOLVED!

I came across this post from [greyhwndz] and I’m struggling with a similar problem:
My Application refuses to allow updates on user-entries in my Ecto-database.
It says no route found for PUT, when I try to update an existing user in my database. (creating new users works just fine, btw.)

[debug] ** (Phoenix.Router.NoRouteError) no route found for PUT /users/8/edit (TempWeb.Router)
    (temp 0.1.0) lib/phoenix/router.ex:405: TempWeb.Router.call/2
    (temp 0.1.0) lib/temp_web/endpoint.ex:1: TempWeb.Endpoint.plug_builder_call/2
    (temp 0.1.0) lib/plug/debugger.ex:136: TempWeb.Endpoint."call (overridable 3)"/2
    (temp 0.1.0) lib/temp_web/endpoint.ex:1: TempWeb.Endpoint.call/2
    (phoenix 1.6.13) lib/phoenix/endpoint/cowboy2_handler.ex:54: Phoenix.Endpoint.Cowboy2Handler.init/4
    (cowboy 2.9.0) /Users/jesperullmann/Projects/temp/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
    (cowboy 2.9.0) /Users/jesperullmann/Projects/temp/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
    (cowboy 2.9.0) /Users/jesperullmann/Projects/temp/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
    (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

In the original topic [kokolegorille] mentioned that, in my case, the router doesn’t get the user_id when updating, but inside my edit.html.form, I am providing the @user reference which should contain the necessary user_id:

<h1>Edit User</h1>
<%= render "user_form.html", Map.put(assigns, :action, Routes.user_path(@conn, :update, @user)) %>

Any ideas on that, how I can fix the update function for user entries in my project? What am I missing here?

Here’s a link to my recent project repository:
[Temp Project]
(https://github.com/y3sp3r/temp/blob/master/lib/temp_web/controllers/user_controller.ex)

Thanks in advance :v:t3:

Looking at your repo there’s this in your router:

resources "/users", UserController, [:index, :show, :edit, :delete]

This doesn’t include :update (nor :create)

3 Likes

LostKobrakai thanks a lot.

Adding the missing

:update

action to the resources, seems to fix it.
how embarrassing…

But am I missing the

:create

action as well?
Thought, this case is already covered through the scope above it, which should also work for logged in users as well.

You can always inspect your routes with…

mix phx.routes
2 Likes