I'm learning elixir and one thing I don't understand the style in which you see maps being arguments in function. The most common place you see this is in controllers like this:
CONTROLLERdef create(conn, %{"league" => league_params}) do
league = %League{}
|> League.changeset(league_params)
|> Repo.insert()
case league do
{:ok, league} ->
conn
|> put_flash(:info, "League Created Successfully.")
|> redirect(to: page_path(conn, :index))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
So, the create/2 function. The second argument looks like this %{"league" => league_params}. Correct me if I'm wrong but that is a map, so why do we reference the value below League.changeset(league_params) instead of the key League.changeset("league")?
This may seem like a silly question but I can't figure this one out and I can't find docs for this question. Thanks for the help.