1
0
Fork 0

Display followers and following

master
Alex Kotov 2 years ago
parent b17ef5fac7
commit e4c1739fd9
  1. 9
      app/controllers/profiles/followers_controller.rb
  2. 9
      app/controllers/profiles/following_controller.rb
  3. 11
      app/views/profiles/followers/index.html.erb
  4. 11
      app/views/profiles/following/index.html.erb
  5. 8
      app/views/profiles/show.html.erb
  6. 5
      config/routes.rb

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

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

@ -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 %>

@ -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 %>

@ -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>

@ -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