From a7791635aa98f012d35f97c3c5288494bbb28e38 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 13 Mar 2024 18:03:43 +0100 Subject: Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- app/controllers/concerns/.keep | 0 app/controllers/concerns/taggable.rb | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 app/controllers/concerns/.keep create mode 100644 app/controllers/concerns/taggable.rb (limited to 'app/controllers/concerns') diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 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 -- cgit v1.2.3