1
0
Fork 0

Display followers and following

This commit is contained in:
Alex Kotov 2021-03-10 16:09:15 +05:00
parent b17ef5fac7
commit e4c1739fd9
6 changed files with 48 additions and 5 deletions

View file

@ -0,0 +1,9 @@
class Profiles::FollowersController < ApplicationController
before_action :set_profile
private
def set_profile
@profile = Profile.find params[:profile_id]
end
end

View file

@ -0,0 +1,9 @@
class Profiles::FollowingController < ApplicationController
before_action :set_profile
private
def set_profile
@profile = Profile.find params[:profile_id]
end
end

View file

@ -0,0 +1,11 @@
<div class="my-4">
<strong>&#10094;&nbsp;<%= link_to @profile.full_name, @profile %></strong>
</div>
<% if @profile.following_profiles.present? %>
<ul>
<% @profile.following_profiles.each do |following_profile| %>
<li><%= link_to following_profile.full_name, following_profile %></li>
<% end %>
</ul>
<% end %>

View file

@ -0,0 +1,11 @@
<div class="my-4">
<strong>&#10094;&nbsp;<%= link_to @profile.full_name, @profile %></strong>
</div>
<% if @profile.followed_profiles.present? %>
<ul>
<% @profile.followed_profiles.each do |followed_profile| %>
<li><%= link_to followed_profile.full_name, followed_profile %></li>
<% end %>
</ul>
<% end %>

View file

@ -1,11 +1,11 @@
<h1><%= @profile.full_name %></h1>
<p>
<%= @profile.following_profiles.count %>
Followers
<%= link_to "#{@profile.following_profiles.count} Followers",
profile_followers_path(@profile) %>
&#8226;
<%= @profile.followed_profiles.count %>
Following
<%= link_to "#{@profile.followed_profiles.count} Following",
profile_following_index_path(@profile) %>
</p>
<p><%= @profile.description %></p>

View file

@ -1,5 +1,8 @@
Rails.application.routes.draw do
root to: 'home#show'
resources :profiles, only: %i[index show]
resources :profiles, only: %i[index show] do
resources :followers, controller: 'profiles/followers', only: :index
resources :following, controller: 'profiles/following', only: :index
end
end