我试图在我的API中实现Guardian并通过它执行登录以获取JWT。我正在看的教程是here。问题是使用类似于他们在示例中使用的用户模型来实现登录。示范代码如下:协议Ecto.Queryable未实现
defmodule PushflightServer.User do
use PushflightServer.Web, :model
use Ecto.Repo
import Ecto.Query
alias PushflightServer.Repo
schema "users" do
field :name, :string
field :email, :string
field :encrypted_password, :string
field :password, :string, virtual: true
field :verify_token, :string
field :verify_date, Ecto.DateTime
timestamps
end
def from_email(nil), do: { :error, :not_found }
def from_email(email) do
IO.write("Before email")
IO.inspect(email)
Repo.one(User, email: email)
end
如果我所说的FROM_EMAIL无论是从内部还是凤凰直IEX -S混合,我得到以下错误:
用户= PushflightServer.User.from_email (“[email protected]”)
** (Protocol.UndefinedError) protocol Ecto.Queryable not implemented for User, the given module does not exist (ecto) lib/ecto/queryable.ex:33: Ecto.Queryable.Atom.to_query/1 (ecto) lib/ecto/repo/queryable.ex:90: Ecto.Repo.Queryable.execute/5 (ecto) lib/ecto/repo/queryable.ex:15: Ecto.Repo.Queryable.all/4 (ecto) lib/ecto/repo/queryable.ex:44: Ecto.Repo.Queryable.one/4
我一定是失去了一些东西简单,但我一直没能找到有关为什么发生这种情况的任何文件。使用Repo插入数据的效果很好。有任何想法吗?