How to view phoenix routes in iex?

How to view route output in iex ?

I know I can do this with mix Phoenix.routes , but would like to do it interactively.

Here is an example of what I would like to do:

 iex -S Phoenix.server mymodel_path 

this gives me this error:

 ** (CompileError) iex:2: undefined function mymodel_path/0 
+10
source share
5 answers

All url / path helpers are compiled into functions in the YourApp.Router.Helpers module. You can import it and call it with the same arguments as in your templates (you would probably pass conn as the first argument, but since we don't have conn in the iex session, you can pass YourApp.Endpoint ):

 iex(1)> import YourApp.Router.Helpers nil iex(2)> page_path(YourApp.Endpoint, :index) "/" iex(3)> task_path(YourApp.Endpoint, :show, 1) "/tasks/1" 

(I have resources "/tasks", TaskController in this project.)

+9
source
 iex> Mix.Tasks.Phoenix.Routes.run '' page_path GET / YourApp.PageController :index user_path GET /users YourApp.UserController :index user_path GET /users/new YourApp.UserController :new user_path GET /users/:id YourApp.UserController :show user_path POST /users YourApp.UserController :create 

Phoenix 1.3 update : mix phoenix.routes is deprecated. Use phx.routes instead. mix phoenix.routes is deprecated. Use phx.routes instead. I.e:

 iex(7)> Mix.Tasks.Phx.Routes.run '' page_path GET / HelloWeb.PageController :index hello_path GET /hello HelloWeb.HelloController :index 
+8
source

Here you can find the relevant documentation for your applications in official documents - http://www.phoenixframework.org/docs/routing#section-path-helpers

Assuming your HelloPhoenix application HelloPhoenix

 iex> import HelloPhoenix.Router.Helpers iex> alias HelloPhoenix.Endpoint iex> user_path(Endpoint, :index) "/users" iex> user_path(Endpoint, :show, 17) "/users/17" iex> user_path(Endpoint, :new) "/users/new" iex> user_path(Endpoint, :create) "/users" 
+1
source

for an umbrella application you should use

 Mix.Tasks.Phx.Routes.run([YourApp.Web.Router]) 
0
source
 YourApp.Web.Router.__routes__() 
0
source

All Articles