Skip to content

Commit

Permalink
[ifmeorg#1713] created ResourceRecommendation class and method
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Warmenhoven committed Apr 7, 2020
1 parent 20a8a14 commit 8dd6ec7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/controllers/moments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions app/services/resource_recommendation.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions app/views/moments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
</div>
<% end %>

<div class="smallMarginTop">
<div class="label">What Resources could help?</div>
<div class='smallMarginTop'>
<div class='label'>What resources could help?</div>
<ul>
<% @resources.first(3).each do |resource| %>
<li><%= link_to resource["name"], resource["link"] %></li>
<% @resources.take(3).each do |resource| %>
<li><%= link_to resource['name'], resource['link'] %></li>
<% end %>
<li><%= link_to 'More...', '/resources' %></li>
</ul>
Expand Down

0 comments on commit 8dd6ec7

Please sign in to comment.