AshSlug is an Ash extension to slugify string attributes on a resource.
The extension is a thin wrapper around the Slugify library, and supports the same options.
defmodule MyDomain.Resource do
@moduledoc false
use Ash.Resource,
domain: MyDomain,
data_layer: Ash.DataLayer.Ets,
extensions: [AshSlug]
ets do
private?(true)
end
attributes do
uuid_primary_key(:id)
attribute(:text, :string, public?: true)
attribute(:text_slug, :string)
end
actions do
create :create do
accept([:text])
change slugify(:text, into: :text_slug)
end
end
end