【问题标题】:What is the difference between param with name and no name param on PhoenixPhoenix 上带名字的参数和不带名字的参数有什么区别
【发布时间】:2018-02-15 23:12:04
【问题描述】:

如果我在router.ex 中写入 (A) 和 (B) 之类的参数。

get "/index/:first/:second", IndexController, :index #(A)
get "/index/:first", IndexController, :index #(B)

应该收集哪一个(1)或(2)?

conn |>
  redirect(to: index_path(conn, :index, first: first, second: second)) #(1)

conn |>
  redirect(to: index_path(conn, :index, first, second: second)) #(2)

我不知道要解释的区别。

【问题讨论】:

    标签: elixir phoenix-framework


    【解决方案1】:

    我不确定我是否理解了这个问题,但我想,首先,在连接和操作名称之后,您传递命名参数,然后,最后一个参数是查询字符串参数,就我记得。

    所以

    get "/index/:first/:second", IndexController, :index #(A)
    

    应该是

    index_path(conn, :index, first, second)
    

    或者如果你想要一些查询参数:

    index_path(conn, :index, first, second, _format: "json")
    

    【讨论】:

      猜你喜欢
      • 2020-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-24
      • 2014-11-23
      • 1970-01-01
      • 1970-01-01
      • 2011-02-22
      相关资源
      最近更新 更多