Access conn.path_params in phoenix app

Hi there,

I’m building a small phoenix application using phoenix 1.2.1 and plug 1.3.0.

In my phoenix app router, I’ve defined a route

get "/car/:name", CarController, :show

and I expect that in the show function of the CarController, the conn.path_params map has the value %{"name" => "<TheValueGivenInTheUrl>"} Unfourtunately, the map is always empty.

In the plug sources, the map conn.path_params is updated in the compile method of the Plug.Router module (it seems to be the only place where this value is updated). But it seems that phoenix doesn’t use this compile function to specify the routes - I’ve set some trace output and the compile method doesn’t seem to be called in my application.

Am I doing something wrong or is this the intended behavior?
Or is there another way to get the path parameters?

I really need to know if a paramter is given in the query, the path or the body of a request.


The path_params member was added in plug 1.3.0 … in a plug-only app I have here, it indeed works with the same get directive you have.

HOWEVER, it seems that the Phoenix.Router as in phoenix 1.2 does not yet implement this. So in an Phoenix app with the identical get line, there is no path_params … and indeed, in the master branch of Phoenix there is support for path_params, but not in the 1.2 branch.

So the next release of Phoenix Framework appears to have this feature … good news / bad news :confused:



that are semi good news :wink:
For now, I’ll take the the id directly from the path_info, e.g:
path_id = List.last(conn.path_info)

That’s far from beeing good code, but works till the next version of Phoenix comes out.