如何在 link 中指定多个参数

How to specify multiple parameters in link

我的router.ex里有这个:

resources "/games", GamesController do
  get "/scores/:student_id", GameScoreController, :new
  post "/scores/:student_id", GameScoreController, :create
end

现在我用以下方式调用它:

link(student.name, to: game_game_score_path(@conn, :new, @game, student_id: student))

但这会创建一个 link:/games/1/scores?student_id=1 而不是 /games/1/scores/1。

如何调用 link 以便它生成正确的 url?

哦,有没有办法摆脱助手中的双重游戏? 我尝试添加为::game_score,但这并没有改变任何东西。

定义路线为:

resources "/games", GameController do
  get "/scores/:student_id", ScoreController, :new
  post "/scores/:student_id", ScoreController, :create
end

注意 Phoenix 中的所有内容都是单数的,包括控制器名称。 URL 是复数,但它是外部的,它并不规定您的代码是如何组织的。

还有 URL 助手:

link(student.name, to: game_game_score_path(@conn, :new, @game, student))

如果你希望controller是GameScoreController,可以通过:as选项自定义生成的helper。 Phoenix 文档中的更多信息:http://hexdocs.pm/phoenix/Phoenix.Router.html#resources/4