diff --git a/app/controllers/v1/admin/permalinks_controller.rb b/app/controllers/v1/admin/permalinks_controller.rb index e28e5a5..ef5bee4 100644 --- a/app/controllers/v1/admin/permalinks_controller.rb +++ b/app/controllers/v1/admin/permalinks_controller.rb @@ -10,7 +10,11 @@ def show end def create - allow_create + allow_create( + { + slug: unique_slug + } + ) end def update @@ -39,11 +43,35 @@ def creatable_attributes ] end + def creatable_relationships + %i[ + event + ] + end + def permitted_filters %i[ slug ] end + + def unique_slug + slug = nil + unique = false + + until slug.present? && unique + slug = three_random_letters + record = Permalink.find_by slug: slug + unique = record.nil? + end + + slug + end + + def three_random_letters + charset = Array('A'..'Z') + Array('a'..'z') + Array.new(3) { charset.sample }.join + end end end end