Programming Phoenix 1.4 hurdle: "no action :update" error thrown via helper.ex

I’m working though the rumbl example in the Programming Phoenix 1.4 book. I added the user and credential code to an example new app and it’s working fine. I decided to add the ability to edit a user, which isn’t part of the rumbl code examples.

I removed the original “only: [:index, :show, :new, :create]” constraints for “/users” in the router, created the edit template and added edit and update functions to usercontroller.ex (taken from another app that used phx.gen.html to add user functionality).

When I try to load the edit page, I get this error:

ArgumentError at GET /users/1/edit

no action :update for helper MyappWeb.Router.Helpers.user_path/2.

The following actions/clauses are supported:

user_path(conn_or_endpoint, :create, params \ )
user_path(conn_or_endpoint, :delete, id, params \ )
user_path(conn_or_endpoint, :edit, id, params \ )
user_path(conn_or_endpoint, :index, params \ )
user_path(conn_or_endpoint, :new, params \ )
user_path(conn_or_endpoint, :show, id, params \ )
user_path(conn_or_endpoint, :update, id, params \ )

[lib/phoenix/router/helpers.ex]

The routes list seems to indicate the update function that’s referenced in the edit template action is valid. I have an update function in the controller.
Does this necessarily mean I need to add something to lib/phoenix/router/helpers.ex?

We need more information to help you, can you show your router, helpers, and controller?

Are you calling Routes.user_path in the edit.html.eex view?
Is it possible you called Routes.user_path(@conn, :update, id) without the ID?

1 Like

Bingo, that was it. Thanks!

I had this:
<%= render “form.html”, Map.put(assigns, :action, Routes.user_path(@conn, :update)) %>

Needed this:
<%= render “form.html”, Map.put(assigns, :action, Routes.user_path(@conn, :update, @user)) %>

2 Likes