From 9da62208272a44bc64a0d198c0eb1a9cd6f82aa3 Mon Sep 17 00:00:00 2001 From: lpichler Date: Mon, 11 Dec 2017 18:37:44 +0100 Subject: [PATCH] Use method for getting proper tag class --- app/models/mixins/assignment_mixin.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/mixins/assignment_mixin.rb b/app/models/mixins/assignment_mixin.rb index 9d363184a6a..bf36d6e08ca 100644 --- a/app/models/mixins/assignment_mixin.rb +++ b/app/models/mixins/assignment_mixin.rb @@ -173,6 +173,10 @@ def assignments end end + def tag_class(klass) + klass == "VmOrTemplate" ? "vm" : klass.underscore + end + # @param target # @option options :parents # @option options :tag_list @@ -196,8 +200,7 @@ def get_assigned_for_target(target, options = {}) tlist = Tagging.where("tags.name like '/managed/%'") .where(:taggable => parents) .references(:tag).includes(:tag).map do |t| - klass = t.taggable_type - lower_klass = klass == "VmOrTemplate" ? "vm" : klass.underscore + lower_klass = tag_class(t.taggable_type) "#{lower_klass}/tag#{t.tag.name}" end tagged_resources = tlist.flat_map { |t| assignments_cached[t] }.uniq