我想要做的是根據可用於數據庫中特定模型的slu dynamically動態路由頂級路徑,例如GitHub如何爲用戶/組織名稱https://github.com/elixir-lang
和https://github.com/phoenixframework
,但我似乎無法在PhoenixFramework中找到我的頭。動態定義菲尼克斯路線中的頂級路線.ex
我到目前爲止已經試過,在我routes.ex
是:
Enum.each(MyApp.Repo.all(MyApp.User), fn section ->
get "/#{user.username}", UserController, :show, assigns: %{"username" => user.username}
end)
但我結束了以下錯誤,當它試圖編譯應用程序:
== Compilation error on file web/router.ex ==
** (ArgumentError) repo MyApp.Repo is not started, please ensure it is part of your supervision tree
lib/ecto/query/planner.ex:91: Ecto.Query.Planner.cache_lookup/3
lib/ecto/query/planner.ex:72: Ecto.Query.Planner.query/4
lib/ecto/repo/queryable.ex:91: Ecto.Repo.Queryable.execute/5
lib/ecto/repo/queryable.ex:15: Ecto.Repo.Queryable.all/4
web/router.ex:25: (module)
(stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:100: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8