Changes to Ecto models

I have a model with a string field that must be at least two characters long:

def changeset(model, params \\ :empty) do
  model
  |> cast(params, @required_fields, @optional_fields)
  |> validate_length(:name, min: 2)
end

      

The problem is that changeet.errors, when legitimately populated, returns:

[name: {"should be at least %{count} characters", 2}]

      

Is this a bug, if not how can I interpolate this tuple?

+3


source to share


1 answer


If you use it with Phoenix, it will automatically take care of you in form_for/4

or when creating a JSON structure. Otherwise, you need to go through it yourself and call it String.replace(string, "%{count}", Integer.to_string(count))

.



+4


source







All Articles