aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/concerns
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r--app/controllers/concerns/.keep0
-rw-r--r--app/controllers/concerns/taggable.rb17
2 files changed, 17 insertions, 0 deletions
diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/controllers/concerns/.keep
diff --git a/app/controllers/concerns/taggable.rb b/app/controllers/concerns/taggable.rb
new file mode 100644
index 0000000..a9bda12
--- /dev/null
+++ b/app/controllers/concerns/taggable.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+# This module provides methods for controllers that have to deal with tag
+# references (i.e. comments and things). This is closely tied to `TagReference`
+# and its polymorphic `:taggable` column.
+module Taggable
+ extend ActiveSupport::Concern
+
+ # Update tag references for the given `object` with tags identified by the
+ # `ids` array.
+ def update_tags!(object:, ids:)
+ object.tag_references.destroy_all
+ return true unless ids
+
+ ids.each { |id| TagReference.create!(tag_id: id, taggable: object) }
+ end
+end