Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/app/helpers/recommendations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module RecommendationsHelper
MAX_USER_RECCOMMENDED_FUNCTIONS = 5

module RecommendationsPartialPath
def to_partial_path
'recommendations/function'
end
end

def more_from_user(user)
most_liked = user.functions.order(likes_count: :desc).first
most_commented = user.functions.order(comments_count: :desc).first
most_saved = user.functions.order(saves_count: :desc).first
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we need also to pass the function we need to ignore here, as this is more functions except the current one.

Also it seems that if we ordered by likes_count + comments_count + saves_count that will give us also a good result, which is the most interacted functions first, the most popular functions for this user.

as you know, any one of these 3 lines can return nil which will miss up your line 15 and you'll have to do compact there so a single query on the database with the criteria and order will be better.


[most_liked, most_saved, most_commented].uniq.map { |obj| obj.extend(RecommendationsPartialPath) }
end
end
13 changes: 11 additions & 2 deletions src/app/views/functions/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<%= content_for :title, sprintf("%s - by: %s", @function.name, @user.name) %>
<%= render 'tags/tags', tags: @function.tags %>
<%= render @function, full: true %>

<div class="columns">
<div class="column">
<%= render 'recommendations/recommendations', function: @function %>
</div>
<div class="column is-four-fifths">
<%= render 'tags/tags', tags: @function.tags %>
<%= render @function, full: true %>
</div>
</div>

<%= render @function.comments %>
<%= render 'comments/form', comment: @comment if can?(@comment, :create) %>
1 change: 1 addition & 0 deletions src/app/views/recommendations/_function.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= link_to "#{function.user.username}/#{function.name}", [function.user, function], class: 'panel-block' %>
6 changes: 6 additions & 0 deletions src/app/views/recommendations/_recommendation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<article class="panel has-background-white">
<p class="panel-heading">
<%= recommendation_title %>
</p>
<%= render functions %>
</article>
2 changes: 2 additions & 0 deletions src/app/views/recommendations/_recommendations.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= render 'recommendations/recommendation', recommendation_title: 'Similar Functions', functions: more_from_user(function.user) %>
<%= render 'recommendations/recommendation', recommendation_title: "More from #{function.user.name}", functions: more_from_user(function.user) %>