我試圖在我的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插入數據的效果很好。有任何想法嗎?