From 8c77f7bebae3793e44ba4309ac5efbbbfa60623f Mon Sep 17 00:00:00 2001 From: stephanie-warmenhoven Date: Tue, 7 Apr 2020 17:11:36 -0700 Subject: [PATCH] [#1713] match resource tag with moment name, why, and fix --- app/controllers/moments_controller.rb | 2 +- app/services/resource_recommendation.rb | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/moments_controller.rb b/app/controllers/moments_controller.rb index 069fb269e4..34f2b2eec3 100644 --- a/app/controllers/moments_controller.rb +++ b/app/controllers/moments_controller.rb @@ -7,7 +7,7 @@ class MomentsController < ApplicationController include MomentsFormHelper include Shared include TagsHelper - include PagesConcern + # include PagesConcern before_action :set_moment, only: %i[show edit update destroy picture] before_action :load_viewers, only: %i[new edit create update picture] diff --git a/app/services/resource_recommendation.rb b/app/services/resource_recommendation.rb index 9c06104d36..79c3b3d131 100644 --- a/app/services/resource_recommendation.rb +++ b/app/services/resource_recommendation.rb @@ -1,3 +1,5 @@ +include PagesConcern + class ResourceRecommendation def initialize(moment) @@ -5,12 +7,17 @@ def initialize(moment) end def resources - resources = JSON.parse(File.read(Rails.root.join('doc', 'pages', 'resources.json'))) all_resources = JSON.parse(File.read(Rails.root.join('doc', 'pages', 'resources.json'))) matched_resources = [] + moment_keywords = [] moment_name = @moment.name.split + moment_why = @moment.why.split + moment_fix = @moment.fix.split + moment_keywords.push(moment_name, moment_why, moment_fix) + moment_keywords = moment_keywords.flatten + moment_keywords = moment_keywords.map(&:downcase) all_resources.each do |resource| - unless (resource['tags'] & moment_name).empty? + unless (resource['tags'] & moment_keywords).empty? matched_resources.push(resource) end end