diff --git a/app/controllers/moments_controller.rb b/app/controllers/moments_controller.rb index 75b16500d0..069fb269e4 100644 --- a/app/controllers/moments_controller.rb +++ b/app/controllers/moments_controller.rb @@ -26,7 +26,8 @@ def index # GET /moments/1.json def show show_with_comments(@moment) - @resources = fetch_resources + @resources = ResourceRecommendation.new(@moment).resources + # @resources = fetch_resources end # GET /moments/new diff --git a/app/services/resource_recommendation.rb b/app/services/resource_recommendation.rb new file mode 100644 index 0000000000..9c06104d36 --- /dev/null +++ b/app/services/resource_recommendation.rb @@ -0,0 +1,20 @@ +class ResourceRecommendation + + def initialize(moment) + @moment = 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_name = @moment.name.split + all_resources.each do |resource| + unless (resource['tags'] & moment_name).empty? + matched_resources.push(resource) + end + end + matched_resources + end + +end \ No newline at end of file diff --git a/app/views/moments/show.html.erb b/app/views/moments/show.html.erb index ee1f8bc966..d6592070ef 100644 --- a/app/views/moments/show.html.erb +++ b/app/views/moments/show.html.erb @@ -43,11 +43,11 @@ <% end %> -
-
What Resources could help?
+
+
What resources could help?