How to specify several parameters in the link

I have this in my router.ex:

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

Now I call this with:

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

But this creates a link: / games / 1 / score? student_id = 1 instead of / games / 1 / score / 1.

How do I call to generate the correct URL?

Oh, and is there a way to get rid of double play in an assistant? I tried adding as :: game_score, but that didn't change anything.

+4
source share
1 answer

Define the route as:

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

Please note that everything in Phoenix is ​​the only one, including the name of the controller. The url is multiple, but it is external, it does not determine how your code will be organized.

And URL helper:

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

, GameScoreController, :as, . Phoenix: http://hexdocs.pm/phoenix/Phoenix.Router.html#resources/4

+2

Source: https://habr.com/ru/post/1607107/


All Articles