Display followers and following
This commit is contained in:
parent
b17ef5fac7
commit
e4c1739fd9
6 changed files with 48 additions and 5 deletions
9
app/controllers/profiles/followers_controller.rb
Normal file
9
app/controllers/profiles/followers_controller.rb
Normal 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
|
9
app/controllers/profiles/following_controller.rb
Normal file
9
app/controllers/profiles/following_controller.rb
Normal 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
|
11
app/views/profiles/followers/index.html.erb
Normal file
11
app/views/profiles/followers/index.html.erb
Normal file
|
@ -0,0 +1,11 @@
|
|||
<div class="my-4">
|
||||
<strong>❮ <%= 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 %>
|
11
app/views/profiles/following/index.html.erb
Normal file
11
app/views/profiles/following/index.html.erb
Normal file
|
@ -0,0 +1,11 @@
|
|||
<div class="my-4">
|
||||
<strong>❮ <%= 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 %>
|
|
@ -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) %>
|
||||
•
|
||||
<%= @profile.followed_profiles.count %>
|
||||
Following
|
||||
<%= link_to "#{@profile.followed_profiles.count} Following",
|
||||
profile_following_index_path(@profile) %>
|
||||
</p>
|
||||
|
||||
<p><%= @profile.description %></p>
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue