Validation error in Phoenix Ecto

887 Views Asked by At

Using Elixir & Phoenix framework here.

I have a signup page where I'm validating the password & password confirmation fields using the validate_confirmation function.

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

If I enter mismatching passwords, I get an error no function clause matching in Gettext.dngettext/6 in the browser - https://i.stack.imgur.com/eDrxE.jpg

I have the latest dependencies before posting this.

The complete stacktrace is available here - http://pastebin.com/XLKav4cu

What am I doing wrong?

1

There are 1 best solutions below

2
On BEST ANSWER

You're using the old style syntax for Ecto. You now need to cast, then pass to the validate_required function

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

See https://hexdocs.pm/ecto/Ecto.html#module-changesets for further details