Strange behaviour of routes

Hello everyone,

I have the following problem. In mein router.ex I defined folowing routes:

post "/users/register", UserRegistrationController, :create
get "/users/log_in", UserSessionController, :new

When I write: mix phx.routes in the terminal he answered me:

user_session_path  GET     /users/log_in                          InESphxWeb.InESphxWeb.UserSessionController :new
user_registration_path  POST    /users/register                        InESphxWeb.UserRegistrationController :create

The first route is wrong. It drives me crazy. I do not know why he is generating InESphxWeb twice. The second routing is OK. But why InESphxWeb twice? Of course it is the wrong path and my app run into panic mode. I can not find, where to change anything to get the correct path. Please help me.

Thank you so much!

Sven

Can you double-check your router.ex for another route that goes to /users/log_in? The order is important, and phx.routes is showing a different one than the declarations.

1 Like

Hi al2o3cr,

Thank you for your answer. The route /users/log_in exists only two times in the router.ex.

Look:

get "/users/log_in", UserSessionController, :new
post "/users/log_in", UserSessionController, :create

regards,
Sven

I found a solution, but I do not understand why this is a problem. VSCode added an alias.

alias InESphx.UserSessionConroller

I saw in a saved version, that this line was in former versions missing. So I removed the alias and it worked. But why is this alias a problem?

regards,
Sven

This happened to someone very recently and feel it’s probably going to happen again!

See here

It’s apparently the language server auto-creating the alias.

2 Likes