Welcome to the forum!
https://hexdocs.pm/plug/Plug.html#moduledoc
The result returned by
init/1
is passed as second argument tocall/2
. Note thatinit/1
may be called during compilation and as such it must not return pids, ports or values that are not specific to the runtime.
So what is passed in the opts
of call/2
isn’t the repo.
From page 89 of Programming Phoenix 1.4
https://media.pragprog.com/titles/phoenix14/code/authentication/listings/rumbl/lib/rumbl_web/controllers/auth.ex
Note how _opts
argument is ignored and the repo is accessed via the Accounts
context.
You may want to have a look at
The error message is based on this:
:erlang.apply({:ok, Rumbl.Repo}, :get, [])
So what happened:
def init(opts) do
Keyword.fetch(opts, :repo)
end
Keyword.fetch/2
returns a tuple that was then passed as the opts
parameter. But even
def init(opts) do
{:ok, repo} = Keyword.fetch(opts, :repo)
repo
end
Would just return the Rumbl.Repo
atom value that is simply the name of the module.