Phoenix Router :new action route going to :show action in controller

Hello all,

I’m getting a strange error where my Phoenix Router is going to the show action in the controller when the route points to the new action.

From the Router

resources "/organizations/:organization_id/network", NetworkMemberController, only: [:index, :show]

resources "/organizations/:organization_id/network", NetworkMemberController, only: [:new, :create, :edit, :update]

These are in separate places because I am piping them through different plugs to authorize the user

From the View

= link "New", to: Routes.network_member_path(@conn, :new, @organization.id)

For some reason it’s reading the /new in the URL bar as an :id

Any thoughts?

Hello @Owens,

You should reorder both resources in your router. I think the resources macro will generate new route before show route.

if the resources with [:index, :show] is defined first in the router, the /new will be caught by show action as id.

2 Likes