Skip to content

Commit 2bc3181

Browse files
committed
feature/Assign users for connect in before_action
1 parent ec42aa3 commit 2bc3181

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class AlertsController < ApplicationController
2+
skip_before_action :assign_users_for_connect
23
layout 'alert'
34
end

app/controllers/application_controller.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base
33
serialization_scope :view_context
44
before_action :configure_permitted_parameters, if: :devise_controller?
55
before_action :set_toast_message, if: -> { params[:notice].present? || params[:alert].present? }
6+
before_action :assign_users_for_connect
67

78
UNAUTHORIZED = 'You do not have access to this page'.freeze
89

@@ -27,4 +28,14 @@ def set_modal_url
2728
sign_in_sign_up_modals_users_path
2829
end
2930
end
31+
32+
def assign_users_for_connect
33+
user_base = User
34+
35+
if user_signed_in?
36+
user_base = user_base.not_followed_by(current_user)
37+
end
38+
39+
@users_for_connect = user_base.order(Arel.sql('RANDOM()')).limit(3)
40+
end
3041
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class ModalsController < ApplicationController
2+
skip_before_action :assign_users_for_connect
23
layout 'modal'
34
end

app/views/layouts/application.html.erb

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,7 @@
8989
%>
9090
<% end %>
9191

92-
<%= render 'shared/cards/card_no_padding' do %>
93-
<h4 class="text-center pt-2">
94-
<%= link_to 'Connect', connect_path, title: 'Search for people to connect with' %>
95-
</h4>
96-
97-
<ul class="divide-y divide-gray-200" data-infinite-scroll-window-target="entries" data-action="scroll@window->infinite-scroll-window#scroll">
98-
<% if user_signed_in? %>
99-
<% User.not_followed_by(current_user).order(Arel.sql('RANDOM()')).limit(3).each do |user| %>
100-
<%= render partial: 'users/connect', locals: { user: user }%>
101-
<% end %>
102-
<% else %>
103-
<% User.order(Arel.sql('RANDOM()')).limit(3).each do |user| %>
104-
<%= render partial: 'users/connect', locals: { user: user }%>
105-
<% end %>
106-
<% end %>
107-
</ul>
108-
<% end %>
92+
<%= render partial: 'shared/connect' %>
10993

11094
<%# <%= render 'shared/cards/card' do %>
11195
<%# <h4 class="text-center">Popular</h4> %>

app/views/shared/_connect.html.erb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
<% if users_for_connect && users_for_connect.any? %>
2-
<div class="card--container card--container-padding-horizontal margin-top" data-controller="list" data-list-url-value="<%= users_path(limit: 5) %>">
3-
<h3 class="text-center no-margin-top margin-bottom">Connect</h3>
4-
<% users_for_connect.each do |user| %>
5-
<%= render partial: 'users/connect', locals: { user: user } %>
6-
<% end %>
7-
<div class="flex flex-end margin-top">
8-
<%= link_to 'More...', connect_path, class: 'padding-right light' %>
9-
</div>
10-
</div>
1+
<% if @users_for_connect.any? %>
2+
<%= render 'shared/cards/card_no_padding' do %>
3+
<h4 class="text-center pt-2">
4+
<%= link_to 'Connect', connect_path, title: 'Search for people to connect with' %>
5+
</h4>
6+
7+
<ul class="divide-y divide-gray-200" data-infinite-scroll-window-target="entries" data-action="scroll@window->infinite-scroll-window#scroll">
8+
<% @users_for_connect.each do |user| %>
9+
<%= render partial: 'users/connect', locals: { user: user }%>
10+
<% end %>
11+
</ul>
12+
<% end %>
1113
<% end %>

0 commit comments

Comments
 (0)