问题
If I write params like (A) and (B) in router.ex
.
get "/index/:first/:second", IndexController, :index #(A)
get "/index/:first", IndexController, :index #(B)
which one should be collect (1) or (2)?
conn |>
redirect(to: index_path(conn, :index, first: first, second: second)) #(1)
conn |>
redirect(to: index_path(conn, :index, first, second: second)) #(2)
I have no idea of difference to explain.
回答1:
I am not sure I understood the question but off the top of my head, I think, first, after connection and action name, you pass the named params and then, the last argument is the query string params, as far as I remember.
So for
get "/index/:first/:second", IndexController, :index #(A)
it should be
index_path(conn, :index, first, second)
or if you want some query params:
index_path(conn, :index, first, second, _format: "json")
来源:https://stackoverflow.com/questions/48810311/what-is-the-difference-between-param-with-name-and-no-name-param-on-phoenix