Phoenix emits "protocal Enumerable not implemnted" error when path helpers get called -
for phoenix app, created 2 routes following:
scope "/", greeter pipe_through :browser "/hello", hellocontroller, :show "/hello/:name", hellocontroller, :show end
with them, app can respond both "/hello" , "/hello/alice" paths.
but, when use path helper hello_path(@conn, :show, "alice")
produce "/hello/alice", phoenix server emits error message:
protocol enumerable not implemented "alice"
the cause simple.
the first route creates 2 helpers hello_path/2
, hello_path/3
, second route creates 1 helper hello_path/4
because hello_path/3
defined.
this hello_path/3
demands enumerable third argument.
how should avoid error?
you can give 1 of route different name using as:
:
get "/hello", hellocontroller, :show "/hello/:name", hellocontroller, :show, as: :hello_with_name
test:
iex(1)> import myapp.router.helpers myapp.router.helpers iex(2)> hello_path myapp.endpoint, :show "/hello" iex(3)> hello_path myapp.endpoint, :show, foo: "bar" "/hello?foo=bar" iex(4)> hello_with_name_path myapp.endpoint, :show, "alice" "/hello/alice" iex(5)> hello_with_name_path myapp.endpoint, :show, "alice", foo: "bar" "/hello/alice?foo=bar"
Comments
Post a Comment