Auto generate a slug
I have the following attributes and would like to autogenerate a
slug
from the name
. Until now I always used https://github.com/wemake-services/ecto_autoslug_field to do this. What is the ash way to solve this?
attributes do
uuid_primary_key :id
attribute :name, :string
attribute :slug, :string
end
GitHub
GitHub - wemake-services/ecto_autoslug_field: Automatically create ...
Automatically create slugs for Ecto schemas. Contribute to wemake-services/ecto_autoslug_field development by creating an account on GitHub.
3 Replies
What you'd want to do is add a "global change", which is done using the top level
changes
DSL. You'd want to do something like this.
And if you want to make it reusable, define your change in a module, and provide opts
like so:
So then you can do change {MakeSlug, field: :field, slug: :slug}
Thanks!
If your question/issue has been resolved, please close the forum post and add the "resolved" tag. Thanks for using the new forum system, hopefully this was and continues to be a good experience 🙂