From d1c390636a930892fb6a9d26b71bcd9d1b2466a7 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 17 Sep 2016 17:12:35 +0800 Subject: [PATCH] Get siblings by metacode type returns only topics with that metacode - fix #538 --- app/controllers/topics_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 846c5469..30ac57fd 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -64,13 +64,14 @@ class TopicsController < ApplicationController topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : [] - @alltopics = policy_scope(Topic.relatives(@topic.id, current_user)).to_a - @alltopics.delete_if do |topic| + alltopics = policy_scope(Topic.relatives(@topic.id, current_user)).to_a + alltopics.delete_if { |topic| topic.metacode_id != params[:metacode].to_i } if params[:metacode].present? + alltopics.delete_if do |topic| !topicsAlreadyHas.index(topic.id).nil? end @json = Hash.new(0) - @alltopics.each do |t| + alltopics.each do |t| @json[t.metacode.id] += 1 end @@ -87,6 +88,7 @@ class TopicsController < ApplicationController topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : [] alltopics = policy_scope(Topic.relatives(@topic.id)).to_a + alltopics.delete_if { |topic| topic.metacode_id != params[:metacode].to_i } if params[:metacode].present? alltopics.delete_if do |topic| !topicsAlreadyHas.index(topic.id.to_s).nil? end