Created
March 19, 2020 00:09
-
-
Save watzon/cad6c9c794e53ad2dce9ccec5293badb to your computer and use it in GitHub Desktop.
EnsureSlug Lucky Mixin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "cadmium_transliterator" | |
module EnsureSlug | |
macro included | |
before_save generate_slug_if_not_exists | |
end | |
def generate_slug_if_not_exists | |
title.value.try do |title| | |
if !slug.value || slug.value.try &.empty? | |
slug.value = Cadmium::Transliterator.parameterize(title) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment