What I would like to do is to dynamically route top level paths depending on slugs that are available for a specific model in the DB, like how GitHub does for user/org names like https://github.com/elixir-lang
and https://github.com/phoenixframework
, but I can't seem to get my head around it in the PhoenixFramework.
What I've tried so far, in my routes.ex
is:
Enum.each(MyApp.Repo.all(MyApp.User), fn section ->
get "/#{user.username}", UserController, :show, assigns: %{"username" => user.username}
end)
but I end up with the following error when it tries to compile the app:
== 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