Function MyApp.Router.Helpers.group_my_groups_path/3 is undefined or private

I have tried for hours to fix this problem. And I’ve spent days trying to just hand one unauthenticated liveview page to an authenticated one … with NO success. Sigh.

I’m getting these two errors:

function MyApp.Router.Helpers.group_my_groups_path/3 is undefined or private
Called with 3 arguments 1. Socket ..., 2. :edit and 3. %Group{...}

AND

inside mygroups.ex, there is a yellow line under  
defp apply_action(socket, :edit, %{"id" => id}) do
with an error that says:
Call to missing or private function.
MyApp.Router.Helpers.group_mygroups_path/3

I’ve run mix phx.routes and here is what I get for live paths:

group_my_groups_path  GET     /mygroups                                 Phoenix.LiveView.Plug :index
group_my_groups_path  GET     /mygroups/:id/edit                        Phoenix.LiveView.Plug :edit
group_my_groups_path  GET     /mygroups/:id/save                        Phoenix.LiveView.Plug :save
group_my_groups_path  GET     /mygroups/new                             Phoenix.LiveView.Plug :new
group_show_path  GET     /mygroups/:id/show/edit                   Phoenix.LiveView.Plug :edit

This is my router:

live "/mygroups", GroupLive.MyGroups, :index
live "/mygroups/:id/edit", GroupLive.MyGroups, :edit
live "/mygroups/:id/save", GroupLive.MyGroups, :save
live "/mygroups/new", GroupLive.MyGroups, :new
live "/mygroups/:id/show/edit", GroupLive.Show, :edit

And here is the problem line in my html.leex:

<span><%= live_patch "Edit", to: Routes.group_mygroups_path(@socket, :edit, group) %></span>

IF I remove that line … everything works. But I need that line! I need to be able to edit the group.

It’s complaining about an arity of 3 but my “mount” and “apply_action” functions both take THREE parameters:

def handle_params(params, _url, socket) do
    {:noreply, apply_action(socket, socket.assigns.live_action, params)}
end

defp apply_action(socket, :index, _params) do
    socket
    |> assign(:page_title, "My Groups")
    |> assign(:group, nil)
end

  defp apply_action(socket, :edit, %{"id" => id}) do
    socket
    |> assign(:page_title, "Edit Group")
    |> assign(:group, Groups.get_group!(id))
  end

I don’t understand why it thinks something is undefined. Everything takes 3 args.

Hi, it looks like you have a typo. Try changing:

<span><%= live_patch "Edit", to: Routes.group_mygroups_path(@socket, :edit, group) %></span>

to:

<span><%= live_patch "Edit", to: Routes.group_my_groups_path(@socket, :edit, group) %></span>

(group_mygroups_path vs group_my_groups_path)

3 Likes

Banging my head on the desk. Can’t believe it was a typo. Thank you!

2 Likes