Skip to content

Commit f146adf

Browse files
committed
initial recommendations
1 parent 4286eef commit f146adf

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module RecommendationsHelper
2+
MAX_USER_RECCOMMENDED_FUNCTIONS = 5
3+
4+
module RecommendationsPartialPath
5+
def to_partial_path
6+
'recommendations/function'
7+
end
8+
end
9+
10+
def more_from_user(user)
11+
most_liked = user.functions.order(likes_count: :desc).first
12+
most_commented = user.functions.order(comments_count: :desc).first
13+
most_saved = user.functions.order(saves_count: :desc).first
14+
15+
[most_liked, most_saved, most_commented].uniq.map { |obj| obj.extend(RecommendationsPartialPath) }
16+
end
17+
end
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<%= content_for :title, sprintf("%s - by: %s", @function.name, @user.name) %>
2-
<%= render 'tags/tags', tags: @function.tags %>
3-
<%= render @function, full: true %>
2+
3+
<div class="columns">
4+
<div class="column">
5+
<%= render 'recommendations/recommendations', function: @function %>
6+
</div>
7+
<div class="column is-four-fifths">
8+
<%= render 'tags/tags', tags: @function.tags %>
9+
<%= render @function, full: true %>
10+
</div>
11+
</div>
12+
413
<%= render @function.comments %>
514
<%= render 'comments/form', comment: @comment if can?(@comment, :create) %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= link_to "#{function.user.username}/#{function.name}", [function.user, function], class: 'panel-block' %>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<article class="panel has-background-white">
2+
<p class="panel-heading">
3+
<%= recommendation_title %>
4+
</p>
5+
<%= render functions %>
6+
</article>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<%= render 'recommendations/recommendation', recommendation_title: 'Similar Functions', functions: more_from_user(function.user) %>
2+
<%= render 'recommendations/recommendation', recommendation_title: "More from #{function.user.name}", functions: more_from_user(function.user) %>

0 commit comments

Comments
 (0)