Phoenix Ecto 中的验证错误

Validation error in Phoenix Ecto

这里使用 Elixir & Phoenix 框架。

我有一个注册页面,我在其中使用 validate_confirmation 函数验证密码和密码确认字段。

def changeset(model, params \ %{}) do
    model
    |> cast(params, @required_fields, @optional_fields)
    |> validate_confirmation(:password)
    |> validate_length(:firstName, min: 2)
end

如果我输入不匹配的密码,我会在浏览器中收到错误 no function clause matching in Gettext.dngettext/6 - http://imgur.com/a/1uZ3N

在发布之前我有最新的依赖项。

完整的堆栈跟踪可在此处获得 - http://pastebin.com/XLKav4cu

我做错了什么?

您正在为 Ecto 使用旧式语法。您现在需要转换,然后传递给 validate_required 函数

def changeset(model, params \ %{}) do
    model
    |> cast(params, [list of all fields])
    |> validate_required([list of required fields])
    |> validate_confirmation(:password)
    |> validate_length(:firstName, min: 2)
end

有关详细信息,请参阅 https://hexdocs.pm/ecto/Ecto.html#module-changesets