Today I Learned

hashrocket A Hashrocket project

Validate data is included in Ecto Changeset

validate_inclusion/4 allows you to validate that specific data is included in a changeset. One way you could use it is by restricting a field's accepted values like this:

changeset
|> validate_inclusion(:direction, ["left", "right"])

if the value of the :direction field is not "left" or "right" a validation error will be added to the changeset

See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.