Skip to content

Commit

Permalink
[ifmeorg#1713] Created resources_url_tags moment helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Warmenhoven committed Apr 24, 2020
1 parent 9d26bd6 commit f98ba85
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
12 changes: 6 additions & 6 deletions app/controllers/moments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def index
def show
show_with_comments(@moment)
@resources = ResourceRecommendations.new(@moment).call
@matched_tags = ResourceRecommendations.new(@moment).matched_tags
@moment_keywords = MomentKeywords.new(@moment).call
@filter_tags = @matched_tags.uniq.map do |t|
"filter[]=#{t}&"
end
@filter_tags = @filter_tags.join
# @matched_tags = ResourceRecommendations.new(@moment).matched_tags
# @filter_tags = @matched_tags.uniq.map do |t|
# "filter[]=#{t}&"
# end
# @filter_tags = @filter_tags.join
@resources_tags = resources_url_tags
end

# GET /moments/new
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/moments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ def get_present_object(element)
moods: element&.mood_names_and_slugs
}
end

def resources_url_tags
matched_tags = ResourceRecommendations.new(@moment).matched_tags
filter_tags = matched_tags.uniq.map do |t|
"filter[]=#{t}&"
end
filter_tags.join
end
end
2 changes: 1 addition & 1 deletion app/views/moments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<% @resources.each do |item| %>
<li><%= link_to item['name'], item['link'] %></li>
<%end %>
<li><%= link_to 'More...', "/resources?#{@filter_tags}" %></li>
<li><%= link_to 'More...', "/resources?#{@resources_tags}" %></li>
</ul>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion spec/services/resource_recommendations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
expect(resources).to eq(available_resource)
end
it 'does not return any matched resources' do
available_resource2 = [{'tags'=> ['self_care', 'anonymous', 'ios', 'communities']}]
available_resource2 = [{'tags'=> ['self-injury', 'tech industry', 'anonymous', 'ios', 'communities']}]
allow(JSON).to receive(:parse) { available_resource2 }
expect(resources).not_to eq(available_resource2)
end
Expand Down

0 comments on commit f98ba85

Please sign in to comment.