Phoenix上带名称的param和没有名称的param有什么区别 [英] What is the difference between param with name and no name param on Phoenix

查看:75
本文介绍了Phoenix上带名称的param和没有名称的param有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If I write params like (A) and (B) in router.ex.

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

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

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 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.

所以

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

应该是

index_path(conn, :index, first, second)

或者如果您需要一些查询参数:

or if you want some query params:

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

这篇关于Phoenix上带名称的param和没有名称的param有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆