Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view phoenix routes in iex?

How do i view the output of a route in iex?

I know i can do this with mix Phoenix.routes but would like to do this 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
like image 770
Doug Avatar asked Jun 04 '16 18:06

Doug


1 Answers

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

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 a resources "/tasks", TaskController in this project.)

like image 75
Dogbert Avatar answered Sep 20 '22 04:09

Dogbert