What is the difference between param with name and no name param on Phoenix

扶醉桌前 提交于 2019-12-11 06:04:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!